CakePHP Auth component redirect issue

后端 未结 2 389
甜味超标
甜味超标 2021-01-13 04:27

I am having trouble getting the Auth component do the redirects I want in a CakePHP 1.2.6 app.

I have a login form that appears on all pages and I want to keep the

相关标签:
2条回答
  • 2021-01-13 04:53

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-13 04:54

    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.

    0 讨论(0)
提交回复
热议问题