[TYPO3-mvc] [Extbase] Object doesn't get initialized.

Alexander Dick alex at dick.at
Thu Oct 14 16:39:27 CEST 2010


Hi, 

Try to remove the assignment in your constructor: $this->items = new Tx_Extbase_Persistence_ObjectStorage;
Normally it should get automagically populated by your repository. 

Cheers
Alex



On Thu, 14 Oct 2010 11:00:10 +0200, Franz Koch <typo3.RemoveForMessage at elements-net.de> wrote:
> Hey,
> 
>> main_domain_model -(m:n)->  user -(1:n)->  item
>>
>> In my user model I initialize the items:
>>
>> class Tx_MyExt_Domain_Model_User extends
>> Tx_Extbase_Domain_Model_FrontendUser {
>>
>> /**
>>   * @var
> Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item>
>> The items of a user
>>   **/
>> protected $items;
>>
>> /**
>>   * Constructor
>>   **/
>> public function __construct() {
>> 	$this->items = new Tx_Extbase_Persistence_ObjectStorage;
>> }
>>
>> ...
>>
>> /**
>>   * Returns the items of the user
>>   *
>>   * @return
>> Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item>  The
>> items of the user
>>   **/
>> public function getItems() {
>> 	return clone $this->items;
>> }
>>
>> ...
>>
>> }
> 
> do you also have a setter method? If not, add it and see if your issue
> is gone (which it should).
> 
> ...
>> However I get the error "Fatal error: __clone method called on
> non-object
>> in ..." when for example the $user->getItems Method gets called during
>> operation.
>>
>> The 'items' attribute is somehow not initialized and it is set to
> 'NULL'.
>>
>> I have no clue about how to trace this error down. I would highly
>> appreciate if somebody could help me out with a hint on where the
> problem
>> could actually be. Is there a general mistake I might have made here?
> 
> IIRC extbase is only calling the constructor on new objects - but not
> objects that get reconstituted from database (which could create wrong
> parameters somehow).
> 
> --
> kind regards,
> Franz Koch
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list