Answer the question
In order to leave comments, you need to log in
Yii2. Redirect user to previous page after authorization
There is a main controller from which all others will inherit. The controller code has the following:
public function init()
{
$this->on('beforeAction', function ($event) {
...
// запоминаем страницу неавторизованного пользователя, чтобы потом отредиректить его обратно с помощью goBack()
if (Yii::$app->getUser()->isGuest) {
$request = Yii::$app->getRequest();
// исключаем страницу авторизации или ajax-запросы
if (!($request->getIsAjax() || strpos($request->getUrl(), 'login') !== false)) {
Yii::$app->getUser()->setReturnUrl($request->getUrl());
}
}
}
...
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question