yii2: 在 denyCallback 中调用未定义的方法 Closure::allows()

Sal*_*ern 2 yii yii2 yii2-advanced-app yii2-basic-app

我使用 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
                ],
            ],
        ];

        }
Run Code Online (Sandbox Code Playgroud)

matchCallback 运行良好,但

denyCallback我有这个错误:

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

我的问题是什么???!

小智 6

denyCallback元素移出规则数组,
它需要与class和在同一级别rules