[TYPO3-english] Constructor injection not working after serializing+deserializing an object? (Jan Kornblum

David Bruchmann david.bruchmann at gmail.com
Mon Jul 20 12:30:22 CEST 2015


Hi Jan,


> > Using __construct in extbase is usually not advised.
>
> But it is advised here:
> http://wiki.typo3.org/Dependency_Injection#Constructor_injection
>
> > Instead you should use  initializeObject(), initializeAction(), or
> > initializeYourActionName().
>
> I need to automatically instance the object manager in my class after
> it has been unserialized (please have a look at my example). I don't
> want to manually inject the object manager "from outside" (e.g. the
> calling controller action).
>
> > Sometimes you even never need those functions as some basics are already
> > setup anyway.
> > Have a look in the classes you extend.
>
> Yes, sometimes. But even @inject doesn't work when my object has been
> unserialized ;) Why?
>
>
Can't you use another example on the page you linked?



class Tx_Foo_Controller_MyController {

/**
 * @var Tx_Extbase_Object_ObjectManagerInterface
 */
protected $objectManager;

/**
 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
 */
public function
injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface
$objectManager) {
$this->objectManager = $objectManager;
}
 public function foo() {
$logFile = $this->objectManager->create('Tx_Foo_LogFile');
}
}



Best Regards,
David


More information about the TYPO3-english mailing list