Cakephp LogOut不起作用

时间:2015-02-17 17:32:54

标签: php cakephp authentication redirect

我有一个大问题 我有3个视图文件夹{admin,teacher,user} 并且在所有这些中都使用index.ctp和logout.ctp 当我想要注销时,url重定向到/ dashboard 我的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');
}

和我的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';

并使用此功能在我的控制器中注销

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

请帮我解决.tnx

1 个答案:

答案 0 :(得分:1)

只需在您的控制器中替换它

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

它会完美运作。