我做了什么
我使用Cookbook的这一部分来创建我的身份验证:链接 完成后,我将字段更改为电子邮件和密码(在AppController.php中):
public function beforeFilter() {
$this->Auth->allow('index');
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
}
发生了什么
登录表单总是说我的密码/电子邮件组合不正确。 经过一段时间的搜索和尝试,我将“$ this-> request-> data”添加到UsersController的login()函数中的Auth-> login()参数中:
public function login(){
$this->layout = 'login';
if ($this->request->is('post')){
if ($this->Auth->login($this->request->data)){
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Ongeldig email adres of wachtwoord. Probeer het AUB opnieuw'));
}
}
}
这有效,但现在我无法使用“$ user ['id']”来获取登录用户ID。它说它不知道$ user变量。
我期望发生什么
首先,它应该在没有我添加参数的情况下记录用户。其次,它应该打印登录用户的id。
我希望有人可以帮我解决这个问题。 提前谢谢!
答案 0 :(得分:0)
字段现在位于authenticate数组中:
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email', ...)
)
)
或者
$this->Auth->authenticate = ...
或
public $components = array(
'Auth' => array(
'authenticate' => ...
)
);
但是,正如PHP自由职业者所说,这是有据可查的。
你使用的是什么食谱版? 2.x一个?