[TYPO3-mvc] problem with constructor method not called?

Franz Koch typo3.RemoveForMessage at elements-net.de
Fri Jan 8 11:33:51 CET 2010


Hi Masi,

>> 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?

It's been created by the repository (getByUid).

> Try to put your code in the initializeObject() method which is also called at wakeup (see abstract
> domain classes).

Thanks, I'll give it a try. But I wonder then, why it's also done in the 
constructors in the blogExample as it won't have any affect there, too. 
They even have a comment there "initialize all ObjectStorage instances 
here" above the constructor.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list