Nuriddin Rashidov
Nuriddin Rashidov

Reputation: 966

Yii2 session destroy and redirect to another page is not working properly

When I destroy session and redirect to page which is related user status, it's redirected, but every time redirecting to home page

In my LoginForm model:

 public  function afterLogin(){

            $this->wrong_pass= 0;
            $this->save();
            if(!isset($this->info)){
                Yii::$app->session->destroy();
                Yii::$app->controller->redirect("hr/notfoundpersonal",302);
            }
        }  

In my behaviors i set these rules:

[
   'allow' => true,
   'actions' => ['login','notfoundpersonal'],
  'roles' => ['?'],
],                  
[
   'allow' => true,
   'actions' => ['logout'],
   'roles' => ['@'],
],

Any suggestion will be helpful,Thanks

Upvotes: 1

Views: 1719

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133380

I think the session destroy delete all the user stored reference based on the session iself and thne the framework cand only drive to the home / default page for accessing operation

Could be you shuold change the default redirection page.

but remember to use

return $this->redirect('hr/notfoundpersonal',302);

for correct redirection

Upvotes: 1

user5201742
user5201742

Reputation:

You should put the url in brackets to transform it to an absolute:

Yii::$app->controller->redirect(["hr/notfoundpersonal"],302);

Info: http://www.yiiframework.com/doc-2.0/yii-web-controller.html#redirect%28%29-detail

Upvotes: 1

Related Questions