Why doesn't TYPO3 have a Page Model in Core?

随声附和 提交于 2021-01-28 05:13:05

问题


When I use the core PageRepository (TYPO3\CMS\Frontend\Page\PageRepository), function getPage(), I get an array returned and not an object, as in many other core repositories. Then I have to build some "magic" for myself in order to inject the Categories or the Page Author as Objects to be used in the Fluid Templates. Question is if it is a kind of "design decision" not to provide a Page Model at all?


回答1:


The PageRepository is not used in Extbase context, so there is no Domain modelling here, because it also is used a lot in backend context and on very low level core execution, where Extbase is not available or it would be to much overhead to boot up Extbase. You can simply map the pages table on to a model of yourself and use proper Domain modelling this way, when using Extbase in your extension. The core does not provide an Extbase Domain model for pages, afaik.




回答2:


It wouldn't make much sense to ship a Extbase Page domain model for various reasons:

  1. TYPO3 itself wouldn't need it.
  2. The model would need to be extremely generic since it cannot know anything about your domain requirements.
  3. Due to this the model would be too generic for basically any domain requirement which in turn would require you to add your own Page domain model anyways.

And yes, the same could be said about the shipped FrontendUser and related classes and one could argue that these should be dropped for the same reasons.




回答3:


You would not have to build an object out of the array for usage in Fluid.

You can also just pass the array to the view. You would use the .-notation just like with an object.

E.g. in the controller:

$this->view->assign('page', $page);

Fluid:

{page.title}


来源:https://stackoverflow.com/questions/59769932/why-doesnt-typo3-have-a-page-model-in-core

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