cakephp logout redirect

爷,独闯天下 提交于 2020-01-16 19:15:16

问题


I have a cakephp app that when I logout it add's admin/login ti the url of the logging in screen. Then when I log in again it says missing controler. I already have a redirect to the Auth logout. If I change that will it still logout?

Original login url:

mydomain.com/res/admin

Url after logout

mydomain.com/res/admin/users/login

After I log in to admin:

mydomain.com/res/admin/admin/login

user controller:

function admin_logout() {
    $this->redirect($this->Auth->logout());
}

回答1:


In AppController you can do something like this

public $components = array(
        'Session',
        'Auth' => array(
        'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'login'),//redirect url
        'authorize' => array('Controller')
    )

);

and in UserController

public function logout() {
        $this->redirect($this->Auth->logout());

}

this worked for me.




回答2:


I solved this by putting a logout redirect in the beforefilter.



来源:https://stackoverflow.com/questions/7547639/cakephp-logout-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!