Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This is the model class for table "person".
  5. *
  6. * The followings are the available columns in table 'person':
  7. * @property integer $id
  8. * @property integer $team_id
  9. * @property string $name
  10. * @property string $email
  11. *
  12. * The followings are the available model relations:
  13. * @property Team $team
  14. */
  15. class Person extends CActiveRecord
  16. {
  17. /**
  18. * @return string the associated database table name
  19. */
  20. public function tableName()
  21. {
  22. return 'person';
  23. }
  24.  
  25. /**
  26. * @return array validation rules for model attributes.
  27. */
  28. public function rules()
  29. {
  30. // NOTE: you should only define rules for those attributes that
  31. // will receive user inputs.
  32. return array(
  33. array('team_id', 'required'),
  34. array('team_id', 'numerical', 'integerOnly'=>true),
  35. array('name, email', 'length', 'max'=>45),
  36. // The following rule is used by search().
  37. // @todo Please remove those attributes that should not be searched.
  38. array('id, team_id, name, email', 'safe', 'on'=>'search'),
  39. );
  40. }
  41.  
  42. /**
  43. * @return array relational rules.
  44. */
  45. public function relations()
  46. {
  47. // NOTE: you may need to adjust the relation name and the related
  48. // class name for the relations automatically generated below.
  49. return array(
  50. 'team' => array(self::BELONGS_TO, 'Team', 'team_id'),
  51. );
  52. }
  53.  
  54. /**
  55. * @return array customized attribute labels (name=>label)
  56. */
  57. public function attributeLabels()
  58. {
  59. return array(
  60. 'id' => 'ID',
  61. 'team_id' => 'Team',
  62. 'name' => 'Name',
  63. 'email' => 'Email',
  64. );
  65. }
  66.  
  67. /**
  68. * Retrieves a list of models based on the current search/filter conditions.
  69. *
  70. * Typical usecase:
  71. * - Initialize the model fields with values from filter form.
  72. * - Execute this method to get CActiveDataProvider instance which will filter
  73. * models according to data in model fields.
  74. * - Pass data provider to CGridView, CListView or any similar widget.
  75. *
  76. * @return CActiveDataProvider the data provider that can return the models
  77. * based on the search/filter conditions.
  78. */
  79. public function search()
  80. {
  81. // @todo Please modify the following code to remove attributes that should not be searched.
  82.  
  83. $criteria=new CDbCriteria;
  84.  
  85. $criteria->compare('id',$this->id);
  86. $criteria->compare('team_id',$this->team_id);
  87. $criteria->compare('name',$this->name,true);
  88. $criteria->compare('email',$this->email,true);
  89.  
  90. return new CActiveDataProvider($this, array(
  91. 'criteria'=>$criteria,
  92. ));
  93. }
  94.  
  95. /**
  96. * Returns the static model of the specified AR class.
  97. * Please note that you should have this exact method in all your CActiveRecord descendants!
  98. * @param string $className active record class name.
  99. * @return Person the static model class
  100. */
  101. public static function model($className=__CLASS__)
  102. {
  103. return parent::model($className);
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement