symfony - Symfony2中用于缓存的内部路由

标签 symfony varnish

我在我的项目中使用内部路由并使用输出 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/

相关文章:

php - 捕获不同的异常类型

php - PDO异常找不到驱动程序

linux - 通过网络连接到 Varnish 4 管理界面

regex - Varnish modsecurity规则语法错误

symfony2 Twig 渲染,抛出异常

php - Symfony2 - 如何验证上传的文件是否为 tex 文件 (LaTex)

symfony - 建议在 Symfony 中的哪个位置修改绑定(bind)表单数据?

python - 如何让 Varnish 停止缓存 ESI 片段

php - 如何在外部/独立的PHP文件(Wordpress外部)中调用Wordpress代码段

WordPress nginx 预览帖子是 404 未找到,但旧帖子正在工作