填写所有必填参数 [英] Filling all mandatory parameters

查看:29
本文介绍了填写所有必填参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Symfony2 内置了一个多语言网站.在基本布局中,有这样的语言切换:

There is a multilingual website built in Symfony2. In the base layout, there is language switch something like this:

<a href="{{ path(app.request.attributes.get('_route'), {_locale: 'en'}) }}">EN</a>
<a href="{{ path(app.request.attributes.get('_route'), {_locale: 'fr'}) }}">FR</a>

这在不改变当前页面的情况下可以很好地切换语言.但是,如果有其他参数,则会因缺少必需参数"而引发异常.如何克服这个问题?

This works fine switching languages without changing the current page. However, if there are other parameters it throws an exception because of 'missing mandatory parameters'. How to overcome this?

推荐答案

你可以这样做:

<a href="{{ path(app.request.attributes.get('_route'), app.request.query.all|merge({'_locale': 'en'})) }}">EN</a>
<a href="{{ path(app.request.attributes.get('_route'), app.request.query.all|merge({'_locale': 'fr'})) }}">FR</a>

这样做是将 _locale 参数与现有的查询参数合并.

What this does is merge the _locale parameter with the existing query parameters.

这篇关于填写所有必填参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆