我已经在 UserController 中编写了这段代码,但无法获得结果。每当我在同一浏览器的两个选项卡中打开管理面板时,如果从一个选项卡注销,则在单击任何菜单时无法从其他选项卡重定向到登录页面。
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));
}
}
最佳答案
使用此代码进行注销操作
public function logout() {
$this->Session->setFlash('you have successfully logged out');
$this->Auth->logout();
return $this->redirect(array('controller' => 'admins', 'action' => 'login'));
}
在 appcontroller 的 beforeFilter 中使用这段代码
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');
}
在 Controller 中使用这个 beforeFilter 函数。
public function beforeFilter() {
parent::beforeFilter();
}
关于jquery - 我正在使用 cakephp 并想知道如何使管理员 session 过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26034465/