diff options
| author | Patrick Seeger <pseeger@ccwn.org> | 2012-04-15 18:37:40 +0200 |
|---|---|---|
| committer | Patrick Seeger <pseeger@ccwn.org> | 2012-04-15 18:37:40 +0200 |
| commit | feb2fe055435e7ecdc657cacee2aaf7dc339dbc9 (patch) | |
| tree | 77fa07572ae7a5a2b6e808c97b9adc7f035059b3 /protected/models/CmsPage.php | |
| parent | ba20ededac6fd68d281603e8c9273f5134d21a4c (diff) | |
Irgendwas in der art von posts
Diffstat (limited to '')
| -rw-r--r-- | protected/models/CmsPage.php | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/protected/models/CmsPage.php b/protected/models/CmsPage.php new file mode 100644 index 0000000..92acf23 --- /dev/null +++ b/protected/models/CmsPage.php @@ -0,0 +1,133 @@ +<?php + +/** + * This is the model class for table "{{cms_page}}". + * + * The followings are the available columns in table '{{cms_page}}': + * @property integer $id + * @property string $content + * @property string $title + * @property string $create_time + * @property string $update_time + * @property integer $status + * @property string $slug + */ +class CmsPage extends CActiveRecord +{ + + + const STATUS_PUBLISHED=1; + const STATUS_DRAFT=2; + const STATUS_DELETED=3; + /** + * Returns the static model of the specified AR class. + * @param string $className active record class name. + * @return CmsPage the static model class + */ + public static function model($className=__CLASS__) + { + return parent::model($className); + } + + /** + * @return string the associated database table name + */ + public function tableName() + { + return '{{cms_page}}'; + } + + /** + * @return array validation rules for model attributes. + */ + public function rules() + { + // NOTE: you should only define rules for those attributes that + // will receive user inputs. + return array( + array('content, title, status, slug', 'required'), + array('status', 'numerical', 'integerOnly'=>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; + } +}
\ No newline at end of file |
