如何获取symfony 2.3中的当前语言环境? [英] how to get the current locale in symfony 2.3?
本文介绍了如何获取symfony 2.3中的当前语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Symfony 2.3中获得当前语言环境?
How can I get the curent locale in Symfony 2.3 ?
我有这样的网址:
/{_locale}/blog/article
,以FR作为默认参数.
我尝试以下方法:
$this->get('request')->getLocale()
I have a url like this:
/{_locale}/blog/article
with FR as a default parameter.
I try the following:
$this->get('request')->getLocale()
但是它总是给我默认参数.而且我知道我可以使用$this->get('session')->set('_locale', 'fr');
but it always give me the default parameter.And i am aware that i can use $this->get('session')->set('_locale', 'fr');
但是问题在于,当用户首次访问我的网站时,他的会话中没有任何存储.
but the problem is that when the user first visit my website he has nothing stored in his session.
推荐答案
您可以通过此方法获取当前语言环境
You can get current locale by this
$request = $this->get('request');
echo $request->getLocale();
这篇关于如何获取symfony 2.3中的当前语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文