我需要在這裏編輯loginredirect會話參數,以便它將重定向到不同的頁面作爲管理員或用戶......事情是。索引硬編碼,它將始終重定向到正常的用戶索引視圖忽略我的代碼重定向管理員用戶。我希望它這樣,如果當前用戶是管理員,它會重定向到admin_index代替cakephp auth loginRedirect
appControler
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'users',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
)
)
);
用戶控制器登錄功能
public function login() {
if($this->Auth->user('account_type')=='admin'){
return $this->Auth->loginRedirect = array('controller' => 'users',
'action' => 'admin_index');
}
elseif($this->Auth->user('account_type')=='user'){
return $this->Auth->loginRedirect = array('controller' => 'users',
'action' => 'view');
}
else {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
首先檢查用戶登錄,如果($這個 - > Auth->登錄()){添加代碼的REST} – Salines 2014-11-04 09:52:43
說行......現在我所有的登錄始終重定向到登錄頁面,但是登錄在頁面頂部的鏈接現在註銷*表示我的用戶確實已登錄* – 2014-11-04 09:59:08