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) »

Changes

Title unchanged

Automate timestamps in ActiveRecord models

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Content changed

[...]
public function rules()
{
return array(
array('title','length','max'=>255),
array('title, created, modified', 'required'),
array('modified','default',

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

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.
[...]
26 0
34 followers
Viewed: 178 727 times
Version: 1.1
Category: Tutorials
Tags:
Written by: dalip
Last updated by: Yang He
Created on: Feb 14, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history