[TYPO3-mvc] problem with constructor method not called?
Martin Kutschker
masi-no at spam-typo3.org
Fri Jan 8 08:57:33 CET 2010
Franz Koch schrieb:
> Hi,
>
> me again. I just stumbled over a strange thing. In my model I have a
> property $contentItems of type Tx_Extbase_Persistence_ObjectStorage. In
> my __construct method of the model, I create a new instance of the class:
>
> public function __construct() {
> $this->contentItems = new Tx_Extbase_Persistence_ObjectStorage();
> }
>
>
> In my function getContentItems I first have to collect the various
> content items and attach them to my property contentItems [1], but if I
> do so I get a php error "Fatal error: Call to a member function attach()
> on a non-object in...". How can this happen?
How was the object created? Did you use "new" or was it created by ExtBase from the repository? In
the latter case the constructor will not be called as the objects are instantiated by some magic
from a serialized "fake object".
Try to put your code in the initializeObject() method which is also called at wakeup (see abstract
domain classes).
Why the objects storages are initialized normally without calling the constructor is still a mystery
to me.
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list