Does retrieving an object from Doctrine2 cause __construct() of the model class to run?
Posted
by
jiewmeng
on Stack Overflow
See other posts from Stack Overflow
or by jiewmeng
Published on 2010-12-24T02:36:53Z
Indexed on
2010/12/26
11:53 UTC
Read the original article
Hit count: 250
zend-framework
|doctrine2
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;
}
© Stack Overflow or respective owner