我刚从Symfony 2.1升级到2.2。我按照这里给出的说明进行了操作:
http://symfony.com/blog/symfony-2-2-0
https://github.com/symfony/symfony/blob/2.2/UPGRADE-2.2.md
之前我的所有代码都运行得很漂亮,但现在有一些问题,在我尝试在我的应用程序中执行某些操作后,框架会在URL中注入“_fragment”。这会改变我的网址:
http://server/app_dev.php/en-GB/
为:
http://server/app_dev.php/_fragment/
然后通过twig将其作为语言环境拾取并使其失败并显示以下错误:
An exception has been thrown during the rendering of a template
("Circular reference detected when adding a fallback catalogue for locale "".")
in "/var/....../HomeBundle/Resources/views/Home/index.html.twig".
2/2 Twig_Error_Runtime: An exception has been thrown during the rendering of a template
("Circular reference detected when adding a fallback catalogue for locale "".")
in "/var/...../HomeBundle/Resources/views/Home/index.html.twig"
1/2 LogicException: Circular reference detected when adding a fallback catalogue for locale "".
部分回溯说:
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException".
CRITICAL - Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Circular reference detected when adding a fallback catalogue for locale "".") in "/var/...../HomeBundle/Resources/views/Home/index.html.twig"." at /var/...../app/cache/dev/classes.php line 6030
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
当我第一次登录应用程序时,它似乎都运行正常,请求列出应该是的语言环境:
_locale "en-GB"
_route "_home_index"
_route_params "Array(_locale => en-GB)"
但是,如果我再单击另一个链接(包括返回同一页面),则会因上述错误而失败并将请求更改为:
_locale "_fragment"
_route "_home_index"
_route_params "Array(_locale => _fragment)"
我的路由(对于上面的示例)如下所示:
Home_Home:
resource: "@HomeBundle/Controller/HomeController.php"
type: annotation
prefix: /{_locale}
defaults: { _locale: en }
我的配置:
framework:
translator: { fallback: en }
default_locale: en
我不认为问题是语言环境处理,而是使用添加到Symfony 2.2的新片段子处理框架。可能是以某种方式调用/激活它? (或者我缺少某种配置)。
答案 0 :(得分:1)
我想我至少发现了这个问题,只需在config.yml中添加一个片段配置项就可以解决这个问题:
framework:
fragments: { path: /_fragment }