在 Symfony2 上使用不同的参数在 URL 中切换语言环境
Switch locale in URL with different arguments on Symfony2
我有 3 个 link 可以在 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>
当我在控制器中没有任何额外参数时,一切都很好。例如(模式:/{_locale})
public function indexAction(){
...
}
不幸的是,当我有一些额外的参数(例如:模式:/page/{id}/{name}/{_locale}
)时,我在这些 links
中得到错误
route has some missing mandatory parameters
有人知道正确的 link 应该是什么样子吗?这应该总是有效 - 当没有参数并且什么时候是 n
或 n + 1
参数时。
或者还有其他更改语言的方法?
您可以在 app.request.attributes
中找到它。
如果你不认识他们:
{{path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge ({'_locale':'pl' })) }}
我有 3 个 link 可以在 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>
当我在控制器中没有任何额外参数时,一切都很好。例如(模式:/{_locale})
public function indexAction(){
...
}
不幸的是,当我有一些额外的参数(例如:模式:/page/{id}/{name}/{_locale}
)时,我在这些 links
route has some missing mandatory parameters
有人知道正确的 link 应该是什么样子吗?这应该总是有效 - 当没有参数并且什么时候是 n
或 n + 1
参数时。
或者还有其他更改语言的方法?
您可以在 app.request.attributes
中找到它。
如果你不认识他们:
{{path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge ({'_locale':'pl' })) }}