Reputation: 771
$this->Model->id = $id;
$this->Model->saveField('field', 'value');
OR
$this->Model->set(array('fieldname' => 'value'));
$this->Model->save();
OR
$this->Model->updateAll(array("fieldName"=>"value"),array("fieldName"=>"condition"));
OR
$this->Model->save($this->request->data);
There are many option in cakephp to update data which also create confusion to choose one.
Thanks in advance..
Upvotes: 0
Views: 100
Reputation: 189
All have their own usage.please find my answers along with ur code.
When you wish to update one column for given id. you can use below code. $this->Model->id = $id; $this->Model->saveField('field', 'value');
It can be update multiple columns for given id. Here you added one field only. so, it will update only one column [affected to one row only]. $this->Model->set(array('fieldname' => 'value')); $this->Model->save();
It will update field for multiple rows on which condition is satisfied. $this->Model->updateAll(array("fieldName"=>"value"),array("fieldName"=>"condition"));
Below line mainly used with insert statement, where all columns need to be saved. it may also used for update row too.
$this->Model->save($this->request->data);
I hope you find your answer.
Upvotes: 1