0

I'm using a repository in Symfony2-controller like this:

$blog = $em->getRepository('BlogBloggerBundle:BlogData')->getBlogData($id);

Before I call it into the twig view through an array.

All works right but the issue is that it make up a footer menu, then, i should call it almost in every action which i need.

How i can call it from a "common" repository every time which i need?

4

2 回答 2

3

创建一个视图响应侦听器,注册一个 twig 变量并在其中添加存储库调用...

...或创建一个 twig 扩展,将从存储库接收的数据公开为全局 twig 变量。

...或者(我的首选)创建一个专用于渲染页脚的控制器并包含这样的页脚:

{{ render(controller('Bundle:controller:action')) }}

在 symfony 主页上的这篇博文中阅读更多关于渲染片段的内容。

于 2013-10-04T15:33:36.487 回答
0

FYI 关于嵌入控制器的官方文档:http: //symfony.com/doc/current/book/templating.html#embedding-controllers

于 2013-10-04T19:48:01.127 回答