Sitansu
Sitansu

Reputation: 891

Cakephp Model save and update without modifying `created` and `modified` fields

Can any body tell how to save and update database table using Model save function without modifying the created and modified fields in cakephp 2.*

Upvotes: 4

Views: 5774

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

If you don’t want the modified field to be updated when saving some data add

'modified' => false

to your $data array

Ref: Saving Data

Hope it helps

Example:

$this->request->data['YourModel']['modified'] = false;

Upvotes: 7

Adrian Bhagat
Adrian Bhagat

Reputation: 114

The documentation states that setting 'modified' to false will stop the modified date from being saved. However, I have found that this causes the Save call to fail without any indication of what is wrong. Using unset on the modified value seems to work, however.

unset( $this->request->data['YourModel']['modified'] );

Documentation: http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-save-array-data-null-boolean-validate-true-array-fieldlist-array

Upvotes: 0

Related Questions