我想load
,edit
和save
記錄與CakePHP 2.0
但我的save
方法不幫我明白問題出在哪裏時獲得generic error
。保存數據使用CakePHP將無法正常工作
如果我試用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我從蛋糕的find
方法得到正確的用戶。
我在哪裏錯了?
它可能無法驗證嗎? – NullUserException
你能建議我一些替代方法來調試無效的fileds而不是'debug($ this-> User-> invalidFields());'? – vitto