L
L
lilwings2020-02-21 16:46:20
Yii
lilwings, 2020-02-21 16:46:20

Yii2 how to specify which controller to apply action in AccessControl?

Here is the code that is written in the AppController from which all the rest are inherited:

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


For an unauthorized user, only action => index is allowed, but there is one such action for each controller, is it possible to indicate that an action belongs to a controller in a rule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cyberlog, 2020-02-21
@lilwings

This should be written in the controller itself, not in the parent class.
Why do this in the parent, if this rule will still apply to 1 controller?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question