I work with zf2.1.3 and doctrine 2. I tried to remove information about my class and understand that it DoctrineModule\Stdlib\Hydrator\DoctrineObjectdoes not work with fields that emphasize it, for example cat_id.
Here is an example:
class Foo
{
private $cat_id;
private $cat_name;
public function getCatId()
{
return $this->cat_id;
}
public function setCatName($name)
{
$this->cat_name = $name;
return $this;
}
public function getCatName()
{
return $this->cat_nome;
}
}
class Bar
{
private $id;
private $name;
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->nome;
}
}
use \DoctrineModule\Stdlib\Hydrator\DoctrineObject;
public function indexAction()
{
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Foo');
$foo = $hydrator->hydrate(array('cat_name' => 'Frank Moraes'), new Foo());
\Zend\Debug\Debug::dump($foo, 'Foo Hydrator');
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Bar');
$bar = $hydrator->hydrate(array('name' => 'Frank Moraes'), new Bar());
\Zend\Debug\Debug::dump($inscrit, 'Bar Hydrator');
}
This code returns the following:
Foo Hydrator
object(Application\Entity\Foo)
private 'cat_id' => null
private 'cat_name' => null
Bar Hydrator
object(Application\Entity\Foo)
private 'id' => null
private 'name' => 'Frank Moraes'
So my question is: why does Doctrine Hydrator not work with fields that underline it? How can I do this job?
Thank!
Edited
Sorry for a long time without an answer. I do not have access to SO at my work!
I tried the following:
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Foo', false);
In the example here, this option falseworks fine.
But it didn’t work when I attach the class to the form!
Does anyone have a key?
source
share