Php 在Symfony2上使用不同参数切换URL中的区域设置

Php 在Symfony2上使用不同参数切换URL中的区域设置,php,symfony,doctrine-orm,twig,multilingual,Php,Symfony,Doctrine Orm,Twig,Multilingual,我有3个链接来切换Symfony2中的区域设置 <a href="{{ path( app.request.get('_route'), {'_locale': 'pl'}) }}"><img alt="Polski" class="flags" src="{{ asset('bundles/gogscms/images/pol.png') }}"></a> <a href="{{ path( app.request.get('_route'), {

我有3个链接来切换Symfony2中的区域设置

 <a href="{{ path( app.request.get('_route'), {'_locale': 'pl'}) }}"><img alt="Polski" class="flags" src="{{ asset('bundles/gogscms/images/pol.png') }}"></a>
 <a href="{{ path( app.request.get('_route'), {'_locale': 'en'}) }}"><img alt="English" class="flags" src="{{ asset('bundles/gogscms/images/eng.png') }}"></a>
 <a href="{{ path( app.request.get('_route'), {'_locale': 'it'}) }}"><img alt="Italiano" class="flags" src="{{ asset('bundles/gogscms/images/ita.png') }}"></a>
不幸的是,当我有一些额外的参数(例如:pattern:
/page/{id}/{name}/{u locale}
)时,我在这些链接中得到了错误

路由缺少一些必需参数

有人知道正确的链接应该是什么样子吗?这应该总是有效的-当没有参数并且是
n
n+1
参数时


或者有其他方法可以更改语言?

您可以在
app.request.attributes
中找到

如果您不认识他们:

{{path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge ({'_locale':'pl' }))  }}

是的,但我不知道我有多少论点。这些链接位于layout.html.twig中,必须自动生成。例如,第一种模式是:/{u locale},第二种模式是:/page/{id}/{name}/{u locale},第二种模式是/news/{id}/{u locale}
Method“parameters”,对象“Symfony\Component\HttpFoundation\ParameterBag”不存在
我使用Symfony2.1-也许这就是原因吧?谢谢帮助,但应该是
app.request.attributes.get(''u route\params')
。现在一切都好了:)
{{path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge ({'_locale':'pl' }))  }}