Does retrieving an object from Doctrine2 cause __construct() of the model class to run?
- by jiewmeng
When I retrieve an object say by
$em->find('Application\Models\User', 1);
or other methods like DQL, findBy*() cause the __construct() of the model class to run? I am having a problem where I set variables there like reference to EntityManager and I find that its not set.
I tried putting a die() in __construct() and it doesn't halt the application. Can I say that if I want to set other properties/fields like EntityManager $em I have to do it some other way? Perhaps something like
protected function getEm() {
if (!isset($this->em)) {
$this->em = \Zend_Registry::get('em');
}
return $this->em;
}