Difference between #5 and #6 of
How to automate timestamps in ActiveRecord models

Revision #6 has been created by wei on Feb 17, 2009, 11:32:10 AM with the memo:

add new line to remove horizontal scrolling code blocks
« previous (#5) next (#7) »


Title unchanged

Automate timestamps in ActiveRecord models

Category unchanged


Yii version unchanged

Tags unchanged

Content changed

public function rules()
return array(
array('title, created, modified', 'required'),

'value'=>new CDbExpression('NOW()'),
'setOnEmpty'=>false,'on'=>'update'), array('created,modified','default',
'value'=>new CDbExpression('NOW()'),

You see the two rules at the end, one changes the modified field when the record's being updated, and the other changes both fields when the record's being created. You'll also see the "new CDbExpression('NOW()')" statement. This passes "NOW()" to the MySQL server and it will not be escaped. MySQL will interpret it as a statement and not as a string. This means that the field types could have been any other date/time type (timestamp, etc.) and it would still work.
25 0
Viewed: 153 416 times
Version: 1.1
Category: Tutorials
Written by: dalip
Last updated by: Yang He
Created on: Feb 14, 2009
Last updated: 5 years ago
Update Article


View all history