0
我正在關注一些使用CakePHP重置遺忘密碼的在線示例。下面是代碼:CakePHP:無法更新數據庫
$temp = $this->User->findByEmail($this->data['User']['email']);
$user = $temp['User']['UID'];
$this->set('email', $this->data['User']['email']);
if($user)
{
$new_salt = UsersController::generateStr();
$new_password = UsersController::generateStr(5);
$temp_password = Security::hash((Security::hash($new_password,'md5',false) . $new_salt), 'md5', false);
$data = array('User' => array('UID' => $user, 'Password' => $temp_password));
$this->User->save($data, false, array('Password'));
$data = array('User' => array('UID' => $user, 'Salt' => $new_salt));
$this->User->save($data, false, array('Salt'));
$to = $this->data['User']['email'];
$subject = "RideShare Password Reset";
$message = "Your new RideShare password is " . $new_password;
$headers = "";
mail($to, $subject, $message, $headers);
$this->Session->setFlash('Your new password has been sent to' . $this->data['User']['email']);
}
當這個代碼執行我的網頁顯示該調試信息:
Query: INSERT INTO `users` (`Password`, `modified`, `created`) VALUES ('81a5392c1d9687811cfeb7e66c887a4a', '2011-07-08 23:53:05', '2011-07-08 23:53:05')
Query: INSERT INTO `users` (`Salt`) VALUES ('HjP1miaias')
但是,當我直接去phpMyAdmin的檢查數據庫我看到值已不算真正到過更新。
任何意見表示讚賞。
我嘗試插入$ this-> User-> id = $ user和$ this-> User-> uid但結果大致相同。特別是數據庫沒有被更新。表中沒有新的行。 – Schemer
其實$ this-> user-> id = $ user會拋出一個關於未定義的User.id的新投訴。 $ this-> User-> uid =給出了和以前相同的結果。 – Schemer
您是否將模型配置爲使用UID而不是id? – JJJ