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

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

                  相关文档推荐

                  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 的问题)

                      <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'>