Answer the question
In order to leave comments, you need to log in
Yii2. How to make a redirect to authorization?
Hello!
Faced a very unpleasant problem, all the solutions found did not help.
I created a project based on yii2-advanced (I work in the backend for now), added a couple of modules (including users).
When an unauthorized user enters the module page, he is redirected to the page with authorization. Everything works fine, except when we go to a page like: project.dev/random_string. In this case, a 404 error page is displayed with all the data available to authorized users.
Those. when working correctly, it should first transfer to the page with authorization, and then to the selected page with an error.
I understand that the problem is somewhere in the configs. Those. access control for site and modules works as specified, but accessing a non-existent module causes this problem.
Code from backend\SiteController
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'login' => 'site/login',
'' => 'site/index'
],
],
Answer the question
In order to leave comments, you need to log in
In this case, a 404 error page is displayed with all the data available to authorized users.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question