hadi saadati
hadi saadati

Reputation: 1

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

Upvotes: 0

Views: 1398

Answers (1)

Supravat Mondal
Supravat Mondal

Reputation: 2594

Simply replace this in your controller

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

It will work perfectly.

Upvotes: 1

Related Questions