我一直在努力解决我的问题,整晚尝试了很多方法来更新用户模型的条目,但我没有想出来。
我尝试使用saveField,updateAll和findBy然后保存,但我所拥有的只是我的数据库上的新条目或没有更新。
这是代码,希望你能帮忙
<?php
public function email_verification($token) {
$this->User->create();
$user = $this->User->findByEmailToken($token);
$this->User->set(array('email_token' => 'valid'), $user);
$this->User->save($user, false);
}
?>
提前致谢
答案 0 :(得分:0)
尝试以下代码:
<?php
public function email_verification($token) {
$user = $this->User->findByEmailToken($token);
$user['User']['email_token'] = 'valid';
if ($this->User->save($user)) {
....
....
} else {
debug($this->User->validationErrors);
}
}
?>
答案 1 :(得分:0)
Ahum:
$this->User->set(array('email_token' => 'valid'), $user);
$this->User->save($user, false);
save()调用使用原始数据保存您的记录.....因为您传入了$ user!
将来自$ this-&gt; user-&gt; set()的电话改为:
$user['User']['email_token'] => 'valid';