Role.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * This is the model class for table "{{role}}".
  4. *
  5. * The followings are the available columns in table '{{role}}':
  6. * @property integer $id
  7. * @property string $name
  8. * @property string $auth_ids
  9. * @property integer $status
  10. * @property string $descr
  11. * @property string $create_date
  12. * @property string $update_date
  13. */
  14. class Role extends CActiveRecord
  15. {
  16. /**
  17. * @return string the associated database table name
  18. */
  19. public function tableName()
  20. {
  21. return '{{role}}';
  22. }
  23. /**
  24. * @return array validation rules for model attributes.
  25. */
  26. public function rules()
  27. {
  28. // NOTE: you should only define rules for those attributes that
  29. // will receive user inputs.
  30. return array(
  31. array('name, create_date, update_date', 'required'),
  32. array('status', 'numerical', 'integerOnly'=>true),
  33. array('name', 'length', 'max'=>20),
  34. array('descr', 'length', 'max'=>255),
  35. array('auth_ids', 'safe'),
  36. // The following rule is used by search().
  37. // @todo Please remove those attributes that should not be searched.
  38. array('id, name, auth_ids, status, descr, create_date, update_date', 'safe', 'on'=>'search'),
  39. );
  40. }
  41. /**
  42. * @return array relational rules.
  43. */
  44. public function relations()
  45. {
  46. // NOTE: you may need to adjust the relation name and the related
  47. // class name for the relations automatically generated below.
  48. return array(
  49. );
  50. }
  51. /**
  52. * @return array customized attribute labels (name=>label)
  53. */
  54. public function attributeLabels()
  55. {
  56. return array(
  57. 'id' => 'ID',
  58. 'name' => '角色名',
  59. 'auth_ids' => '权限ID(用逗号隔开)',
  60. 'status' => '是否可用,默认1表示可用,0表示已经删除',
  61. 'descr' => '简介',
  62. 'create_date' => '创建时间',
  63. 'update_date' => '更新时间',
  64. );
  65. }
  66. /**
  67. * Retrieves a list of models based on the current search/filter conditions.
  68. *
  69. * Typical usecase:
  70. * - Initialize the model fields with values from filter form.
  71. * - Execute this method to get CActiveDataProvider instance which will filter
  72. * models according to data in model fields.
  73. * - Pass data provider to CGridView, CListView or any similar widget.
  74. *
  75. * @return CActiveDataProvider the data provider that can return the models
  76. * based on the search/filter conditions.
  77. */
  78. public function search()
  79. {
  80. // @todo Please modify the following code to remove attributes that should not be searched.
  81. $criteria=new CDbCriteria;
  82. $criteria->compare('id',$this->id);
  83. $criteria->compare('name',$this->name,true);
  84. $criteria->compare('auth_ids',$this->auth_ids,true);
  85. $criteria->compare('status',$this->status);
  86. $criteria->compare('descr',$this->descr,true);
  87. $criteria->compare('create_date',$this->create_date,true);
  88. $criteria->compare('update_date',$this->update_date,true);
  89. return new CActiveDataProvider($this, array(
  90. 'criteria'=>$criteria,
  91. ));
  92. }
  93. /**
  94. * Returns the static model of the specified AR class.
  95. * Please note that you should have this exact method in all your CActiveRecord descendants!
  96. * @param string $className active record class name.
  97. * @return Role the static model class
  98. */
  99. public static function model($className=__CLASS__)
  100. {
  101. return parent::model($className);
  102. }
  103. }