• <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 应用程序中设置全局语言值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  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>