2012-02-14 102 views
1

我UserController.php已注销功能,看起来像这样

function logout() 
    { 
     $this->Session->destroy('User'); 
     $this->Session->setFlash('You\'ve successfully logged out.'); 
     var_export($this->Session->read('User')); 

     //$this->redirect('login'); 
    } 

我认为用户/ index.ctp

<?php echo $this->Html->link('Logout', array('controller' => 'users', 'action' => 'logout')); ?> 

当我点击“注销”的var_export仍显示所有用户数据,如果我回去用户/ index.ctp它仍然显示我,即使我在我的UserController.php如果用户设置我检查该网页

function beforeFilter() 
{ 
    $this->__validateLoginStatus(); 
} 


function __validateLoginStatus() 
    { 
     if($this->action != 'login' && $this->action != 'logout') 
     { 
      if($this->Session->check('User') == false) 
      { 
       $this->redirect('login'); 
      } 
     } 

它不重定向到登录页面,只是把我带到索引页面。 }

+0

$ this-> Session-> destroy('User');它也将起作用.. – 2012-06-14 12:03:13

回答

3
$this->Session->destroy(); 

的销毁方法删除会话cookie并存储在临时文件系统中的所有会话数据。

要移除的用户,请使用更好的删除。

$this->Session->delete('User'); 
+0

$ this-> Session-> delete('User')和$ this-> Session-> destroy('User')之间的区别是什么? – CodeCrack 2012-02-14 20:04:32

+0

$ this-> Session-> delete()清空一个Session,$ this-> Session-> destroy()销毁PHP会话,然后创建一个新的会话。 – 2012-02-14 22:04:36