A
A
Alexander2015-10-13 23:28:53
Yii
Alexander, 2015-10-13 23:28:53

Redirect if user doesn't match role?

Behavior in controller:

public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['login', 'error'],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['logout', 'index', 'register'],
                        'allow' => true,
                        'roles' => ['create-poster'],
                        'denyCallback' => function(){
                            $this->redirect('/');
                        }
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

1a2c758c.png
But it doesn't want to redirect, it just gives 403.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Villarou, 2015-10-14
@kentuck1213

Somehow this was discussed on the git . Actually your decision seems to be in the last answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question