我正在尝试load
,edit
并save
记录CakePHP 2.0
但我generic error
在该save
方法中得到一个不能帮助我理解问题所在的方法。
如果我尝试debug($this->User->invalidFields());
我得到一个empty array
,但我false
从$this->User->save()
条件中得到。
这是我收到错误的控制器操作:
public function activate ($code = false) {
if (!empty ($code)) {
// if I printr $user I get the right user
$user = $this->User->find('first', array('activation_key' => $code));
if (!empty($user)) {
$this->User->set(array (
'activation_key' => null,
'active' => 1
));
if ($this->User->save()) {
$this->render('activation_successful');
} else {
// I get this error
$this->set('status', 'Save error message');
$this->set('user_data', $user);
$this->render('activation_fail');
}
debug($this->User->invalidFields());
} else {
$this->set('status', 'Account not found for this key');
$this->render('activation_fail');
}
} else {
$this->set('status', 'Empty key');
$this->render('activation_fail');
}
}
当我尝试该操作时,test.com/users/activate/hashedkey
我会收到带有消息的activation_fail
模板页面。Save error message
如果我printr
是$user
var,我会从 cake 的find
方法中获得正确的用户。
我哪里错了?