Revision #9 has been created by Maurizio Domba Cerin on Jun 17, 2011, 10:16:17 AM with the memo:
changed text to mention Gii instead of yiic, and explained better the beforeSave() variant
« previous (#8) next (#10) »
How to automate timestamps in ActiveRecord models
ways to automate the setting of timestamps in yii ActiveRecord models. Two
ways you can d
1. Via rules()
2. Via beforeSave()
To start off we need a database table.
[...]`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Following this we'll gener
with the Yii shell tool:
model Node Nodes
To create the crud functionality we need to type this:
The first way you can do it is via your model's rules. Here is an example.
$this->created = new CDbExpression('NOW()');
$this->modified = new CDbExpression('NOW()');
These are simple and elegant solutions to this issue.