CakePHP Auth component redirect issue

耗尽温柔 提交于 2019-12-01 05:46:18

Add parent::beforeFilter(); to beforeFilter in the user controller:

function beforeFilter() {
    $this->Auth->autoRedirect = false;
    parent::beforeFilter();
}

You can also replace the redirect with this to the login method of your user controller:

$this->redirect($this->Auth->redirect());

Auth->redirect() returns the url where the user landed before being taken to the login page or Auth->loginRedirect.

Aditya P Bhatt

Put this code to your controller:

function beforeFilter() {
    $this->Auth->allow('login', 'logout');
    $this->Auth->autoRedirect = false;
    parent::beforeFilter();
}

and, add this for the login page:

function login() {
    if($this->Auth->User()) {
        $this->redirect(array('action'=>'welcome'), null, true);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!