[TYPO3-mvc] Extbase 1.3: initializeObject() changed?

Michael Knoll mimi at kaktusteam.de
Wed Feb 2 17:24:54 CET 2011


Hi Roberto,

whenever you create a domain object via construct() ($foo = new $bar()) 
and not via persistence-managing (e.g. repository etc. 
$repository->findAll()), your initializeObject() method is not called. 
So you should create a __construct() method in your domain object, that 
initializes all object storages:

public function __construct() {
     $this->foreinObjectsProperty = new 
Tx_Extbase_Persistence_ObjectStorage();
}

After that, it should work fine!

Greetings

Michael



Am 02.02.11 12:17, schrieb roberto blanko:
> Hello devs,
>
> in my current Extbase extensions, I use initializeObject() in my models to
> init attributes, especially ObjectStorages for related objects.
>
> Since the Update to TYPO3 4.5 and therefore Extbase 1.3, I continuesly
> encounter PHP errors of the following type:
>
> Fatal error: Call to a member function attach() on a non-object
>
> This happens when I try to attach on object to an attribute that is beeing
> initialized as Tx_Extbase_Persistence_ObjectStorage. However in many cases
> the attribute remains NULL and the error above is thrown. It seems to me as
> if initializeObject() is not called every time the domain object is being
> created.
>
> $this->virtualChildren = new Tx_Extbase_Persistence_ObjectStorage();
>
> This is how my initializeObject() looks like:
>
> public function initializeObject()
> {
>      parent::initializeObject();
>      $this->children = new Tx_Extbase_Persistence_ObjectStorage();
> }
>
> Important notice: The attribute is not being persisted to a database. It's
> just a virtual attribute which contains values during runtime only.
>
> Regards
> roberto



More information about the TYPO3-project-typo3v4mvc mailing list