在我的 cake 2.2 应用程序中,我在应用程序控制器中设置了以下 beforeFilter() :
public function beforeFilter() {
//Configure AuthComponent
// Admin
if($this->Auth->user('group_id') == '12') {
$this->Auth->allow('admin_index');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => TRUE);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->set("group", "admin");
// Staff
}
if($this->Auth->user('group_id') == '13') {
$this->Auth->allow('admin_index');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => TRUE);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->set("group", "staff");
所以基本上我希望在会话到期时将所有用户与用户组相关的所有用户发送到 /users/login 。这适用于用户,但任何管理员用户都会被重定向到 admin/users/login 并在用户控制器错误中显示 Missing 方法(因为这不是管理员方法)。由于某种原因,'admin' => FALSE 不起作用。
那么,无论用户类型如何,如何让所有用户重定向到 /users/login 的非管理方法/url
// Users
}
if($this->Auth->user('group_id') == '14') {
$this->Auth->allow(array('controller' => 'pages', 'action' => 'index', 'admin' => FALSE));
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => FALSE);
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
$this->set("group", "user");
}
// General logout redirect (including expired session redirect)
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => FALSE);
}