共享symfony base控制器中所有视图中的公共内容
我正在使用ezplatform,并试图找出如何自动将公共cms内容共享到所有页面,而无需为每个视图编写单独的控制器 这是yml文件的简单摘录:共享symfony base控制器中所有视图中的公共内容,symfony,content-management-system,ezpublish,ezplatform,Symfony,Content Management System,Ezpublish,Ezplatform,我正在使用ezplatform,并试图找出如何自动将公共cms内容共享到所有页面,而无需为每个视图编写单独的控制器 这是yml文件的简单摘录: root_folder: controller: "AppBundle:Homepage:homepage" match: Id\Location: 58 article_container: controller: "AppBundle:ArticleContainer:articleContainerChildr
root_folder:
controller: "AppBundle:Homepage:homepage"
match:
Id\Location: 58
article_container:
controller: "AppBundle:ArticleContainer:articleContainerChildren"
match:
Identifier\ContentType: "article_container"
article_one_column:
template: "full/article_one_column.html.twig"
match:
Identifier\ContentType: "article_one_column"
除了最后一个,这三个简单的匹配都有自己的自定义控制器
前两个匹配命中扩展基本控制器的控制器。
在基本控制器中,我们有一个标准的渲染函数,其调用方式如下:
return $this->render(
'full/article_container.html.twig',
[
'location' => $location,
'content' => $currentContent,
'articles' => $articles,
'articleLocations' => $locations,
]
);
$parameters = array_merge($parameters, [
'main_navi' => $navigation,
'mega_navi_data' => $navigation,
'quotes' => $contentRenderer->getQuotesData(),
'featured_articles' => $contentRenderer->getFeaturedArticles(),
'contact_form' => $this->getContactForm(),
]);
return parent::render($view, $parameters, $response);
所述渲染函数如下所示:
return $this->render(
'full/article_container.html.twig',
[
'location' => $location,
'content' => $currentContent,
'articles' => $articles,
'articleLocations' => $locations,
]
);
$parameters = array_merge($parameters, [
'main_navi' => $navigation,
'mega_navi_data' => $navigation,
'quotes' => $contentRenderer->getQuotesData(),
'featured_articles' => $contentRenderer->getFeaturedArticles(),
'contact_form' => $this->getContactForm(),
]);
return parent::render($view, $parameters, $response);
如您所见,我们只是将原始参数与所有页面所需的一些公共数据合并。此数据用于“maga navi”和页脚内容
现在的问题是,当我们尝试加载一个文章列
页面时,
由于它不使用自定义控制器,因此不会加载公共数据
导致细枝错误的页眉和页脚是必需的
问题:
我们如何在不为每种数据类型编写自定义控制器的情况下向所有路由提供公共内容?您不必为每种内容类型创建控制器。如果可以的话,您想要的是将数据注入到视图中 使用自定义控制器是其中一个选项,对于要注入的通用内容,也可以使用 我们已经将这个概念(除此之外:)与ChildrenProvider的概念捆绑在一起 此外,您还提到希望在视图中插入与页眉和页脚相关的信息,以便在布局中获得它们。听起来很奇怪。使用eZ和Symfony,您可以从视图渲染控制器,您可以独立于视图渲染页眉和页脚。(这可能是你应该做的) 但是对于孩子们,我喜欢使用监听器而不是自定义控制器。
它在Novactive bundle中进行管理,但如果您自己进行管理,请小心,pre_content_view侦听器将在每个视图(行、完整等)上触发,通常,您只想在完整视图中插入内容。作为任何发现此内容的人的注意事项。如果您确实打算使用自定义控制器,并且希望使用此预渲染事件(非常棒)。请注意,您的自定义控制器(如果它只是调用std渲染)不会自动触发此事件,您必须手动调用它。从ez的核心进行Std视图渲染当然会触发事件。。。如果在从控制器进行简单渲染时,有一个简单的方法调用来触发所有std事件,那就太酷了。。。