开发者

Problem with updating record in database

I have problem to update user data in cakephp.

When I submit form I have this data in $this->data:

Array
(
    [User] => Array
        (
            [first_name] => Dusan
            [last_name] => Stojanovic
            [native_language_id] => 25
        )
)

but, when i try to update it with:

$this->User->id = $id;
$this->User-&g开发者_Python百科t;save($this->data)

model is not saved, because of validation. They try to validate field which don't exist in $this->data array (like invalid password, email etc.). How I can fix this so I can update only fields that exist in $this->data array?


To properly do this you should set the validation rules' on option to create only and/or set require to false.

For a quickfix, supply a $fieldlist of fields you want to save:

$this->User->save($this->data, true, array('first_name', 'last_name', 'native_language_id'));


you can do this:

$this->data['User']['id'] = $id

because of the ['id'] cakephp recognizes the array as data that will update a dataset and will not create a new data set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜