简体   繁体   中英

cakePHP Routers/ loginRedirect not working after logout

OK, another one for the cakephp ninjas today.. Here it is : I have a login/logout system implemented.. I am using $components attr in the AppController, and using the Auth config key to set up loginRedirect and logoutRedirect.. The code looks like this :

public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Auth' => array(
        'loginRedirect' => array(   
            'controller' => 'posts',
            'action' => 'index'
        ),
        'logoutRedirect' => array(  
            'controller' => 'users',
            'action' => 'login'
        ),
        'authorize' => array('Controller') 
    )
);

The logout action looks like this :

 public function logout() {
        $this->Session->setFlash(__('You are now logged out.'));
        return $this->redirect($this->Auth->logout());
    }

Here's the deal.. Whenever I logout through the above logoutRedirect, and then log in, the user is not redirected to posts/index somehow.. and since I ve got DebugKit setup I tried to check whats going on an realised that within the cake Request Params, the controller is set to 'pages' and the action is 'display'.. This lead me to try and logout by manually entering the logout action URL in the address bar.. and guess what?! it works, and the user is redirected to the posts/index page.. So anyone knows how i can fix this issue im having? Or can point me towards a good source from which i can understand what and why is this happening exactly! thanks

Try this

$this->Auth->logout(); $this->redirect(some url);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM