问题
I'm using CakePHP 2.0, I have the following save code:
$to_save = array(
'User' => array(
'uid'=>$uid,
'firstname'=>$firstname,
'lastname'=>$lastname,
'bio'=>$bio,
'gender'=>$gender,
'link'=>$link,
'username'=>$username,
'email'=>$email
)
);
$this->User->create();
if( $this->User->save( $to_save ) ){
echo 'User was saved.';
}else{
echo 'User not saved.';
}
But it always output 'User not saved.' Thanks for any help!
回答1:
If there are no query errors, you probably have some validation rules in the model that prevent the data from saving. You can add debug( $this->User->invalidFields() ) to see if and which fields fail validation.
来源:https://stackoverflow.com/questions/9394080/cakephp-2-0-cannot-save