How to automate timestamps in ActiveRecord models

Comparing #7 with #8

Revision #8 was created by nye.cat nye.cat on Jun 15, 2011, 6:04:44 PM.

Deleted 'else' in the beforeSave Example

Content

[...]
[php]
public function beforeSave() {
if ($this->isNewRecord)
$this->created = new CDbExpression('NOW()');
else $this->modified = new CDbExpression('NOW()'); return parent::beforeSave(); } These are simple and elegant solutions to this issue.