1 <?php
2
3
4
5 class TimestampBehavior extends CActiveRecordBehavior {
6 7 8
9 public $createtime = 'createtime';
10 11 12
13 public $updatetime = 'updatetime';
14 public $integer_timestamps = true;
15
16 public function beforeValidate($on) {
17 if(isset($this->Owner->tableSchema->columns[$this->createtime]))
18 if ($this->Owner->isNewRecord)
19 if($this->integer_timestamps)
20 $this->Owner->{$this->createtime} = time();
21 else
22 $this->Owner->{$this->createtime} = new CDbExpression('NOW()');
23
24 if(isset($this->Owner->tableSchema->columns[$this->updatetime]))
25 if($this->integer_timestamps)
26 $this->Owner->{$this->updatetime} = time();
27 else
28 $this->Owner->{$this->updatetime} = new CDbExpression('NOW()');
29
30 return true;
31 }
32 }
33
34