2014-09-25 44 views
0

我已经在UserController中编写了此代码,但无法获得结果。每当我在同一浏览器的两个选项卡中打开管理面板,并且如果从一个选项卡注销,当点击任何菜单时,从其他标签重定向到登录页面。我正在使用cakephp,想知道如何过期管理员会话

function beforeFilter() 
    {  
     if(($this->request->prefix)=='admin') 
     $this->Auth->allow(); 
     $chk = $this->Session->check('Admin'); 
     $this->disableCache(); 
     if(@$this->Session->read('Admin') && ($this->request->action == 'admin_login')) 
    { 
     $this->redirect(array('action' => 'dashboard','admin' => true)); 
    } 

} 

回答

0

使用此代码注销操作

public function logout() { 
     $this->Session->setFlash('you have successfully logged out'); 
     $this->Auth->logout(); 
     return $this->redirect(array('controller' => 'admins', 'action' => 'login')); 
    } 

在beforeFilter在AppController中使用此代码

public function beforeFilter() { 
    $this->Auth->loginAction = array('admin' => false, 'controller' => 'admins', 'action' => 'login'); 
    $this->Auth->logoutAction = array('admin' => false, 'controller' => 'admins', 'action' => 'logout'); 
    $this->Auth->allow('index','login','forgot','changepass'); 

} 

在控制器使用该beforeFilter功能。

public function beforeFilter() { 

     parent::beforeFilter(); 

    }