我无法在cakephp.org的教程中注销我的项目

时间:2011-11-10 10:02:02

标签: cakephp acl logout

我遵循cakephp教程,当我登录我的帐户时, 教程链接是: http://book.cakephp.org/view/1543/Simple-Acl-controlled-Application  ,我无法注销: 我在logout方法中的代码是

    function logout() {
    $this->Session->setFlash('Good-Bye');
    $this->redirect($this->Auth->logout());
}

,登录代码为:

    function login() {

    if ($this->Session->read('Auth.User')) {
        $this->Session->setFlash('You are logged in!');
        $this->redirect('/', null, false);
    }
}

此方法位于users_controller内。 但是当我使用这个URL时

http://localhost/newacl/users/logout

我回来了

http://localhost/newacl/users

我看这篇文章

您已登录!

因此我无法退出。 你能说出会发生什么,并说出我在做什么工作。

2 个答案:

答案 0 :(得分:3)

我知道这是一个古老的话题,但也许对其他人有帮助。

似乎添加了这个

function beforeFilter() {
 $this->Auth->allow('login','logout');
}

到UsersController解决注销问题

答案 1 :(得分:2)

你重定向你退出的东西的问题..在你的App_controller.php beforeFilter

中添加以下代码
$this->Auth->loginError = "Wrong credentials. Please provide a valid username and password.";

            $this->Auth->authError = "You don't have sufficient privilege to access this resource.";

            $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');

            $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');

            $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');

在你注销

 $this->Session->setFlash('You Succefully Logged Out');
         $this->Auth->logout(); 
         $this->redirect('/');  
在您的登录中

试试这个

if($this->Auth->user('id')){
     $this->Session->setFlash('You are logged in!');
      $this->redirect('/', null, false);
}
希望这对你有帮助....