我在我的项目中使用内部路由并使用输出 url 进行缓存(Varnish)。
代码 :
_internal:
resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
prefix: /parts
和 Twig (基本 Twig )包含代码:
{% render "my_controller:getHeaderAction" with {}, { "standalone" : true } %}
{% render "my_controller:getSidebarAction" with {}, { "standalone" : true } %}
{% render "my_controller:getFooterAction" with {}, { "standalone" : true } %}
这会生成如下网址:
/parts/my_controller%3AgetHeaderAction/none.html
/parts/my_controller%3AgetSidebarAction/none.html
/parts/my_controller%3AgetFooterAction/none.html
我试图为 SidebarAction 获取单独的 Url,例如:
/parts/prefix/my_controller%3AgetSidebarAction/none.html
但不知道怎么做,因为内部路由会自动生成 url。
有什么解决方法吗?
谢谢你的时间。
最佳答案
您需要手动为my_controller:getSidebarAction
定义路由规则,然后使用url
标记进行渲染。
假设您使用的是Symfony 2.3,则语法为{{ render_esi(url('latest_news', { 'max': 5 })) }}
注意,我使用的是特殊的render_esi
标记,它是在Symfony 2.2中添加的,目的是为反向代理(如Varnish)添加更好的ESI支持。
更多信息在这里http://symfony.com/doc/current/book/http_cache.html#using-esi-in-symfony2
关于symfony - Symfony2中用于缓存的内部路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16753719/