读书人

yiif的Behavior例子

发布时间: 2012-09-09 09:27:54 作者: rapoo

yiif的Behavior事例

<?phpclass AutoTimestampBehavior extends CActiveRecordBehavior {     /**    * The field that stores the creation time    */    public $created = 'created';    /**    * The field that stores the modification time    */    public $modified = 'modified';      public function beforeValidate($on) {        if ($this->Owner->isNewRecord)            $this->Owner->{$this->created} = new CDbExpression('NOW()');        else            $this->Owner->{$this->modified} = new CDbExpression('NOW()');         return true;        }}

?

model:

public function behaviors(){    return array(        'AutoTimestampBehavior' => array(            'class' => 'application.components.AutoTimestampBehavior',            //You can optionally set the field name options here        )    );}
?

读书人网 >编程

热点推荐