T
T
tobik-872016-02-25 19:40:50
Yii
tobik-87, 2016-02-25 19:40:50

How to restrict guest access to the admin panel?

Good evening. Can you please tell me how in Yii it is possible to restrict a guest's access to the admin panel and, when entering any page of the admin panel, give him a login view? What is the best way to do this? Inherit one controller to another? Use the init() method? Tried to make a simple redirect:

if (Yii::$app->user->isGuest) {
            return $this->redirect('/admin/login');
        }

But a cyclic redirect occurs, the page forwards to itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2016-02-25
@fornit1917

Use AccessControl filter in base controller www.yiiframework.com/doc-2.0/guide-security-author...

L
Lumore, 2016-02-25
@Lumore

That's what RBAC is for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question