• <small id='1T43c'></small><noframes id='1T43c'>

      <bdo id='1T43c'></bdo><ul id='1T43c'></ul>
    <tfoot id='1T43c'></tfoot>
      <i id='1T43c'><tr id='1T43c'><dt id='1T43c'><q id='1T43c'><span id='1T43c'><b id='1T43c'><form id='1T43c'><ins id='1T43c'></ins><ul id='1T43c'></ul><sub id='1T43c'></sub></form><legend id='1T43c'></legend><bdo id='1T43c'><pre id='1T43c'><center id='1T43c'></center></pre></bdo></b><th id='1T43c'></th></span></q></dt></tr></i><div id='1T43c'><tfoot id='1T43c'></tfoot><dl id='1T43c'><fieldset id='1T43c'></fieldset></dl></div>
        <legend id='1T43c'><style id='1T43c'><dir id='1T43c'><q id='1T43c'></q></dir></style></legend>

        在 Yii2 应用程序中设置全局语言值

        Set global language value in Yii2 application(在 Yii2 应用程序中设置全局语言值)
          <tbody id='VAsCS'></tbody>

          <legend id='VAsCS'><style id='VAsCS'><dir id='VAsCS'><q id='VAsCS'></q></dir></style></legend>
            <i id='VAsCS'><tr id='VAsCS'><dt id='VAsCS'><q id='VAsCS'><span id='VAsCS'><b id='VAsCS'><form id='VAsCS'><ins id='VAsCS'></ins><ul id='VAsCS'></ul><sub id='VAsCS'></sub></form><legend id='VAsCS'></legend><bdo id='VAsCS'><pre id='VAsCS'><center id='VAsCS'></center></pre></bdo></b><th id='VAsCS'></th></span></q></dt></tr></i><div id='VAsCS'><tfoot id='VAsCS'></tfoot><dl id='VAsCS'><fieldset id='VAsCS'></fieldset></dl></div>

              <small id='VAsCS'></small><noframes id='VAsCS'>

              <tfoot id='VAsCS'></tfoot>

                <bdo id='VAsCS'></bdo><ul id='VAsCS'></ul>
                1. 本文介绍了在 Yii2 应用程序中设置全局语言值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以在哪里设置全局语言(基于用户的 cookie)?如何让它在整个应用程序(控制器、视图等)中工作?

                  Where can I set language (based on user's cookie) globally? How to make it work in the whole application (controllers,views, etc.) ?

                  在文档中我找到了 Yii::$app->language = ''; 但是,我可以在哪里编写逻辑以正确的方式更改语言?

                  In documentation I found Yii::$app->language = ''; but, where I can write my logic to change the language in right way?

                  推荐答案

                  你应该使用

                  Yii::$app->language = ''; 
                  

                  在所有控制器的父级控制器中.父类应该在 components 文件夹中,如果它不可用,则使用类似

                  inside the controller that is parent to all your controllers. The parent class should be inside the components folder, and if it is not available than create the component with something like

                  use yiiwebController;
                  class MyController extends Controller
                  {
                      public function init()
                      {
                          parent::init();
                          #add your logic: read the cookie and then set the language
                      }
                  }
                  

                  在那之后,你必须确保你的所有控制器都扩展了你新创建的 MyController 而不是原来的.

                  After that, you have to be sure that all your controllers extends your newly created MyController instead of the original one.

                  希望能帮到你.

                  这篇关于在 Yii2 应用程序中设置全局语言值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)

                  1. <small id='Pg6eG'></small><noframes id='Pg6eG'>

                      <tbody id='Pg6eG'></tbody>
                    • <i id='Pg6eG'><tr id='Pg6eG'><dt id='Pg6eG'><q id='Pg6eG'><span id='Pg6eG'><b id='Pg6eG'><form id='Pg6eG'><ins id='Pg6eG'></ins><ul id='Pg6eG'></ul><sub id='Pg6eG'></sub></form><legend id='Pg6eG'></legend><bdo id='Pg6eG'><pre id='Pg6eG'><center id='Pg6eG'></center></pre></bdo></b><th id='Pg6eG'></th></span></q></dt></tr></i><div id='Pg6eG'><tfoot id='Pg6eG'></tfoot><dl id='Pg6eG'><fieldset id='Pg6eG'></fieldset></dl></div>

                        <legend id='Pg6eG'><style id='Pg6eG'><dir id='Pg6eG'><q id='Pg6eG'></q></dir></style></legend>
                      1. <tfoot id='Pg6eG'></tfoot>

                        • <bdo id='Pg6eG'></bdo><ul id='Pg6eG'></ul>