0

我刚刚从 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

我的所有代码之前都运行良好,但现在在我尝试在我的应用程序中执行某些操作后,框架将“_fragment”注入到 URL 中存在某种问题。这正在改变我的网址:

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 中的新片段子处理框架。可能它以某种方式被调用/激活?(或者我缺少某种配置)。

4

1 回答 1

1

我想我至少发现了这个问题,只需在 config.yml 中添加一个片段配置项即可解决该特定问题:

framework:
    fragments:       { path: /_fragment }
于 2013-04-08T06:34:27.237 回答