0
大家好我都試過了基本身份驗證的登錄名和其工作正常,但與管理員前綴使用時CakePHP的Auth->登錄()不工作與管理前綴的登錄操作
$this->Auth->login() is returning false.
這裏是我的代碼片段,
在模型我已經加入,
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
在AppController中添加以下代碼,
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index', 'admin' => true),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'admin' => true)
)
);
在UsersController我的管理員登錄如下,
public function admin_login() {
if ($this->request->is('post')) {
//$this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']);
debug($this->request->data['User']['password']);
debug($this->Auth->login());
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
在上文中,
調試($這 - >請求 - >數據[ '用戶'] [ '密碼'])正在返回正確的密碼,但
debug($ this-> Auth-> login())返回false。
我無法弄清楚它返回false的原因是什麼,是否需要爲管理路由完成任何更改。
我知道這已經很長一段時間了,但我可以知道你是如何解決這個問題的嗎?我有同樣的問題。這是工作之前,但它已經有一段時間,因爲我訪問管理頁面,現在它不工作。感謝您的回覆。 – Leah