Skip to content

Instantly share code, notes, and snippets.

@crisu83
Created June 27, 2013 19:54
Show Gist options
  • Save crisu83/5879797 to your computer and use it in GitHub Desktop.
Save crisu83/5879797 to your computer and use it in GitHub Desktop.
Example file generated by yii-app Gii model generator.
<?php
/**
* This is the model class for table "reply".
*
* The followings are the available columns:
* @property string $id
* @property string $threadId
* @property string $alias
* @property string $subject
* @property string $body
* @property integer $status
*
* The followings are the available relations:
* @property Thread $thread
*/
class Reply extends ActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Reply 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 'reply';
}
/**
* @return array the behavior configurations (name=>config).
*/
public function behaviors()
{
return array_merge(parent::rules(), array(
));
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array_merge(parent::rules(), array(
array('threadId, alias, body, status', 'required'),
array('status', 'numerical', 'integerOnly'=>true),
array('threadId', 'length', 'max'=>10),
array('alias, subject', 'length', 'max'=>255),
// The following rule is used by search().
array('id, threadId, alias, subject, body, status', 'safe', 'on' => 'search'),
));
}
/**
* @return array relational rules.
*/
public function relations()
{
return array_merge(parent::relations(), array(
'thread' => array(self::BELONGS_TO, 'Thread', 'threadId'),
));
}
/**
* @return array customized attribute labels (name=>label).
*/
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), array(
'id' => t('label', 'ID'),
'threadId' => t('label', 'Thread'),
'alias' => t('label', 'Alias'),
'subject' => t('label', 'Subject'),
'body' => t('label', 'Body'),
'status' => t('label', 'Status'),
));
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider.
*/
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('threadId',$this->threadId,true);
$criteria->compare('alias',$this->alias,true);
$criteria->compare('subject',$this->subject,true);
$criteria->compare('body',$this->body,true);
$criteria->compare('status',$this->status);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment