forecho
- forecho 赞了评论
不建议对入口文件index.php的修改,推荐的方法是在配置文件中(比如frontend/config/main.php)用behavior配置:
return [ 'id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'frontend\controllers', // behavior 'on beforeRequest' => function ($event) { $l_saved = null; if (true){ # use cookie to store language $l_saved = Yii::$app->request->cookies->get('locale'); }else{ # use session to store language $l_saved = Yii::$app->session['locale']; } $l = ($l_saved)?$l_saved:'en-US'; Yii::$app->sourceLanguage = 'en'; Yii::$app->language = $l; return; }, // 组件 'components' => [ 'user' => [ ......
处理多语言设置的action处
/** * 设定语言: 1) 设置cookie,2) 跳转回原来的页面 * 访问网址 - http://.../site/language?locale=zh-CN * @return [type] [description] */ public function actionLanguage() { $locale = Yii::$app->request->get('locale'); if ($locale){ #use cookie to store language $l_cookie = new yii\web\Cookie(['name' => 'locale', 'value' => $locale, 'expire' => 3600*24*30,]); $l_cookie->expire = time() + 3600*24*30; Yii::$app->response->cookies->add($l_cookie); } $this->goBack(Yii::$app->request->headers['Referer']); }
入口文件在高级版本是init之后产生的,默认不会被放到git库。
php yii xx
- forecho 2015-09-19 已签到连续签到1天,获得了5个金钱
- forecho 2015-09-17 已签到连续签到1天,获得了5个金钱
- forecho 发表了说说搭建一个这个 http://cookbook.getyii.com 欢迎大家来提交翻译,点击右上角「更新」即可参与。
- forecho 发布了源码GetYii 重大更新