V
V
VicTHOR2021-02-10 18:46:21
Yii
VicTHOR, 2021-02-10 18:46:21

Why doesn't AccessRule work?

Registered in the behaviors of the SiteController here is such a filter

'access' => [
            'class' => AccessControl::class,
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['@'],
                ],
                [
                    'actions' => ['login'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
            ],
            'denyCallback' => function($rule, $action) {
                return Yii::$app->response->redirect(['site/login']);
            },
        ],

Now we need to set such a filter for all controllers. Registered in the config
'bootstrap' => ['log', 'access'],
'components' => [
        'access' => [
            'class' => AccessControl::class,
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['@'],
                ],
                [
                    'controllers' => [SiteController::class],
                    'actions' => ['login'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
            ],
            'denyCallback' => function($rule, $action) {
                return Yii::$app->response->redirect(['site/login']);
            },
        ],
and the rule completely stopped working, why?

UPD:
indicated 'controllers' => ['site'], did not help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question