true), array('status', 'in', 'range'=>array(1,2,3)), array('title, slug', 'length', 'max'=>255), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, content, title, create_time, update_time, status, slug', 'safe', 'on'=>'search'), //array('title, status', 'safe', 'on'=>'search'), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'content' => 'Content', 'title' => 'Title', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'status' => 'Status', 'slug' => 'Slug', ); } /** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $criteria->compare('content',$this->content,true); $criteria->compare('title',$this->title,true); $criteria->compare('create_time',$this->create_time,true); $criteria->compare('update_time',$this->update_time,true); $criteria->compare('status',$this->status); $criteria->compare('slug',$this->slug,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } public function getUrl() { return Yii::app()->createUrl('cms', array( 'slug'=>$this->slug, )); } protected function beforeSave() { if(parent::beforeSave()) { if($this->isNewRecord) { $this->create_time=$this->update_time=new CDbExpression('NOW()'); //$this->author_id=Yii::app()->user->id; } else $this->update_time=new CDbExpression('NOW()'); return true; } else return false; } }