3.7.2.3 created and modified
By defining a created or modified field in your database table as datetime fields, CakePHP will recognize those fields and populate them automatically whenever a record is created or saved to the database (unless the data being saved already contains a value for these fields).
The created and modified fields will be set to the current date and time when the record is initially added. The modified field will be updated with the current date and time whenever the existing record is saved.
Note: A field named updated will exhibit the same behavior as modified. These fields need to be datetime fields with the default value set to NULL to be recognized by CakePHP.
If you have updated, created or modified data in your $this->data (e.g. from a Model::read or Model::set) before a Model::save() then the values will be taken from $this->data and not automagically updated.
Either use unset($this->data['Model']['modified']), etc. Alternatively you can override the Model::save() to always do it for you:-
class AppModel extends Model {
//
//
function save($data = null, $validate = true, $fieldList = array()) {
//clear modified field value before each save
if (isset($this->data) && isset($this->data[$this->name]))
unset($this->data[$this->name]['modified']);
if (isset($data) && isset($data[$this->name]))
unset($data[$this->name]['modified']);
return parent::save($data, $validate, $fieldList);
}
//
//
}
class AppModel extends Model {////function save($data = null, $validate = true, $fieldList = array()) {//clear modified field value before each saveif (isset($this->data) && isset($this->data[$this->name]))unset($this->data[$this->name]['modified']);if (isset($data) && isset($data[$this->name]))unset($data[$this->name]['modified']);return parent::save($data, $validate, $fieldList);}////}


























