How can I use an injected object in the constructor?

可紊 提交于 2019-12-06 09:03:19

To achieve this, I can use so-called constructor injection. The ObjectManagerInterface is defined as an argument of the constructor and then automatically injected by Extbase:

/**
 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
 */
protected $objectManager;

public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
    $this->objectManager = $objectManager;
    $this->standaloneView = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');
    $this->standaloneView->setFormat('html');
}

As an alternative to lorenz answer, you could use the lifecycle-method initializeObject(). It will be called after dependency injection has been done.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!