[TYPO3-dev] Model Class __construct() never called

Steffen Müller typo3 at t3node.com
Mon Apr 21 21:18:25 CEST 2014


Hi.

On 21.04.2014 00:33 g4-lisz at tonarchiv.ch wrote:
> There's one strange thing: One of the model class its __construct()
> method gets nerver called, even if some instances are successfully loaded.
> I also put a die(...) into the construct method - no effect!
> 

I guess that happens when objects are reconstituted with unserialize().

Solution: Use the method initializeObject() instead of __construct()

unserialize() triggers the __wakeup() method of a model, which is
inherited from
\TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject::__wakeup()

"If a method with the name initializeObject() exists, it is called after
all dependencies have been injected and configured; so you can use this
method for further initialization work." [1]

-- 
cheers,
Steffen

Active Contributor TYPO3 CMS

TYPO3 Blog: http://www.t3node.com/
Twitter: @stmllr - https://twitter.com/stmllr

[1]
http://forge.typo3.org/projects/typo3v4-mvc/wiki/Dependency_Injection_%28DI%29#initializeObject-as-object-lifecycle-method




More information about the TYPO3-dev mailing list