I have following config a component user
'user' => [
'identityClass' => 'app\models\web\User',
'enableAutoLogin' => true,
'loginUrl'=>['/backend/login'],
],
I have 2 modules backend and frontend. I want if user go to the backend part need use following rule 'loginUrl'=>['/backend/login'] and if to thefrontend part this rule 'loginUrl'=>['/frontend/login']. How can I do that?
For any module or controller you can redirect to your login action using AccessControl behavior in module or controller:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['index'],
'allow' => true,
'roles' => ['@'],
],
],
'denyCallback' => function($rule, $action) {
return Yii::$app->response->redirect(['/your/login/url']);
},
],
];
}
Or in Module class file:
public function init()
{
parent::init();
Yii::$app->user->loginUrl = ['/your/login/url'];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With