Take user back to previous page after logging in?

后端 未结 6 990
故里飘歌
故里飘歌 2021-01-20 16:18

I have a controller called Accounts, with the views signin and signout.

The corresponding functions look like this:

function signin()
{
    if (!empt         


        
6条回答
  •  北恋
    北恋 (楼主)
    2021-01-20 16:48

    Use the AppController and UsersController to set it up

    In AppController beforeFilter action

    $referer = Router::url($this->url, true);
    $this->Auth->loginAction = array('controller'=>'users','action'=>'login','?'=>['referer'=>$referer]);
    

    In UsersController login action

    if($this->Auth->login())
    {
     $this->Session->setFlash(__('Logged in successfully !'));
    $redirect = $this->request->query('referer');
    if(!empty($redirect))
     {
       return $this->redirect($this->Auth->redirectUrl($redirect));
     }else{
        return $this->redirect($this->Auth->redirectUrl());                 
     }
    }
    

提交回复
热议问题