【问题标题】:yii2:Call to undefined method Closure::allows() in denyCallbackyii2:在denyCallback中调用未定义的方法Closure::allows()
【发布时间】:2017-01-29 08:28:06
【问题描述】:

我使用 Yii2 框架 这是我在ShippingController中的行为功能

  public function behaviors()
        {
        return [
            'access' => [
                'class' => \yii\filters\AccessControl::className(),
                'rules' => [
                    // deny all POST requests
//                        [
//                        'actions' => ['index', 'create'],
//                        'allow' => TRUE,
//                    ],
                        [
                        'actions' => ['index', 'create', 'init'],
                        'allow' => true,
                        'roles' => ['?'],
                        'matchCallback' => function ($rule, $action)
                            {
                            return $action->controller->redirect('action');
                            }
                    ],
                    'denyCallback' => function ($rule, $action)
                        {
                        return $action->controller->redirect('not');
                        }
                // everything else is denied
                ],
            ],
        ];

        }

matchCallback 效果很好,但是

denyCallback 我有这个错误:

错误 调用未定义的方法 Closure::allows()

我的问题是什么???!

【问题讨论】:

    标签: yii yii2 yii2-advanced-app yii2-basic-app


    【解决方案1】:

    denyCallback元素移出规则数组
    它需要与classrules 处于同一级别

    【讨论】:

      猜你喜欢
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 2015-05-11
      • 2020-03-29
      • 2016-10-29
      相关资源
      最近更新 更多