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

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

        <bdo id='Bj7sp'></bdo><ul id='Bj7sp'></ul>

        <legend id='Bj7sp'><style id='Bj7sp'><dir id='Bj7sp'><q id='Bj7sp'></q></dir></style></legend>
      1. <tfoot id='Bj7sp'></tfoot>
      2. Yii2 全局过滤器/行为强制用户首先进行身份验证

        Yii2 global filter/behavior to force user to authenticate first(Yii2 全局过滤器/行为强制用户首先进行身份验证)
      3. <legend id='cMTXn'><style id='cMTXn'><dir id='cMTXn'><q id='cMTXn'></q></dir></style></legend>

          <tfoot id='cMTXn'></tfoot>
            <bdo id='cMTXn'></bdo><ul id='cMTXn'></ul>

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

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

                    <tbody id='cMTXn'></tbody>
                1. 本文介绍了Yii2 全局过滤器/行为强制用户首先进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的 Yii2 应用程序中,我试图强制所有用户进行身份验证.如果他们尚未通过身份验证,则应将其重定向到登录页面.

                  In my Yii2 application I'm trying to force all users to be authenticated. If they're not already authenticated they should be redirected to the login page.

                  在 Yii1 中,我通过创建一个类来检查用户是否登录并将该类附加到我的主配置文件中的 onBeginRequest 行为.

                  In Yii1 I did this by creating a class that would check if a user was logged in and attaching that class to the onBeginRequest behavior in my main config file.

                  // Yii 1
                  'behaviors' => array(
                      'onBeginRequest' => array(
                          'class' => 'application.components.RequireLogin',
                      )
                  ),
                  

                  如何在 Yii2 中获得相同的行为?我知道我可以使用行为来做到这一点,但我不想将此行为添加到我的主配置文件中,因此首先检查所有请求以进行身份验证.

                  How can I get the same behavior in Yii2? I know I can use behavior to do this, but I wan't to add this behavior to my main config file so all requests are first checked for authentication.

                  工作行为方法如下所示:

                  The working behaviors method looks like this:

                  // Yii2
                  public function behaviors() {
                      return [
                          'access' => [
                              'class' => AccessControl::className(),
                              'rules' => [
                                  [
                                      'actions' => ['login', 'error'],
                                      'allow' => true,
                                  ],
                                  [
                                      'allow' => true,
                                      'roles' => ['@'],
                                  ],
                              ],
                          ],
                      ];
                  }
                  

                  推荐答案

                  好的,所以我不得不添加以下代码下面 'components' =>[...]

                  Ok, so I had to add the following code below 'components' => [...]

                   'as beforeRequest' => [
                      'class' => 'yiifiltersAccessControl',
                      'rules' => [
                          [
                              'actions' => ['login', 'error'],
                              'allow' => true,
                          ],
                          [
                  
                              'allow' => true,
                              'roles' => ['@'],
                          ],
                      ],
                  ],
                  

                  阅读更多关于格式的信息:http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#configuration-format

                  Read more about the format: http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#configuration-format

                  这篇关于Yii2 全局过滤器/行为强制用户首先进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                      <bdo id='N52eg'></bdo><ul id='N52eg'></ul>
                          <tbody id='N52eg'></tbody>

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

                          <legend id='N52eg'><style id='N52eg'><dir id='N52eg'><q id='N52eg'></q></dir></style></legend>

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