简体   繁体   中英

Cakephp LogOut Not work

i have a big problem i have 3 view folder {admin , teacher , user } and in all of them use index.ctp , and logout.ctp when i want to logout ,url redirect to /dashboard my appcontroller.php

  public $components = array( 'Cookie', 'Session', 'Auth' => array( 'loginRedirect' => array('controller' => 'users', 'action' => 'index'), 'logoutRedirect' => array('controller' => 'users', 'action' => 'login') )); // only allow the login controllers only public function beforeFilter() { $this->response->disableCache(); $this->Auth->allow('login','logout'); } 

and my routes.php

 Router::connect('/', array('controller' => 'users', 'action' => 'login')); /** * ...and connect the rest of 'Pages' controller's URLs. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); Router::connect('/dashboard', array('controller' => 'users', 'action' => 'index')); Router::connect('/login', array('controller' => 'users', 'action' => 'login')); Router::connect('/logout', array('controller' => 'users', 'action' => 'logout')); /** * Load all plugin routes. See the CakePlugin documentation on * how to customize the loading of plugin routes. */ CakePlugin::routes(); /** * Load the CakePHP default routes. Only remove this if you do not want to use * the built-in default routes. */ require CAKE . 'Config' . DS . 'routes.php'; 

and use this function for logout in my controller

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

pls help my to solve that.tnx

Simply replace this in your controller

public function logout()
{
    $this->Auth->logout();
    $this->redirect( '/dashboard' );
}

It will work perfectly.

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