CakePHP 2.0 cannot save

2019-08-22 16:27发布

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!

标签: cakephp save
1条回答
forever°为你锁心
2楼-- · 2019-08-22 16:49

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.

查看更多
登录 后发表回答