V
V
Viktor Yanyshev2018-04-09 10:53:41
Yii
Viktor Yanyshev, 2018-04-09 10:53:41

"Global" authentication in yii2?

How can I make a "global" user authentication, that is, no matter what page the user gets to, it should be redirected to the page with the login form.
Writing beforeAction() { Yii:$app->user->isGuest -> redirect } in each controller is not exactly impressive.
Create an AccessController controller in which there will be beforeAction(), inherit it from yii\web\Controller, and all other controllers inherit from AccessController, as a solution, yes, but what about wedge a controller for the sake of one event? You also have to keep track of the presence of parent::beforeAction in each controller

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem, 2018-04-09
@proudmore

You have the Access Control Filter for that . Declare it in the controller's behaviors() and you'll be happy.

M
Maxim Fedorov, 2018-04-09
@Maksclub

There is not enough Middleware functionality :)
Making basic controllers for each section of the application is such a thing :)
Here is a discussion on Middleware in Yii2
https://github.com/yiisoft/yii2/issues/15438
* Or you can take Laravel, it's all out of the box there is (... sly laughter...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question