TYPO3 Best practice assigning cObject data to view since getContentObject() is depricated

邮差的信 提交于 2019-12-11 17:19:53

问题


I was wondering how this is solved in modern extensions, but could not figure it out. Most of them just magical using e.g. {data.uid} inside their views without any $view->assign('data',...)

In my old actions I had used something like this:

public function myAction() {
  $data = $this->configurationManager->getContentObject()->data;
  $this->view->assign('data', $data);
}

Since getContentObject() is marked as deprecated in v8, it should be replaced with getContentObjectRenderer(), but the Configuration-Manager has not such a function.


回答1:


OK after playing around a while and searching through a lot of classes, it seems that the original solution is still valid, the deprecated message applied to another class which has no meaning in this case:

$cObjectData = $this->configurationManager->getContentObject()->data;
$view->assign('data', $cObjectData);

The Extension File Scanner was miss leading me with its warning, there is no deprecated message inside the logs using this solution,... sorry!



来源:https://stackoverflow.com/questions/54239832/typo3-best-practice-assigning-cobject-data-to-view-since-getcontentobject-is-d

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