Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This is the model class for table "categories".
  5. *
  6. * The followings are the available columns in table 'categories':
  7. * @property integer $id
  8. * @property string $title
  9. * @property integer $parent_id
  10. */
  11. class Categories extends CActiveRecord
  12. {
  13. /**
  14. * Returns the static model of the specified AR class.
  15. * @return Categories the static model class
  16. */
  17. public static function model($className=__CLASS__)
  18. {
  19. return parent::model($className);
  20. }
  21.  
  22. /**
  23. * @return string the associated database table name
  24. */
  25. public function tableName()
  26. {
  27. return 'categories';
  28. }
  29.  
  30. /**
  31. * @return array validation rules for model attributes.
  32. */
  33. public function rules()
  34. {
  35. // NOTE: you should only define rules for those attributes that
  36. // will receive user inputs.
  37. return array(
  38. array('title, parent_id', 'required'),
  39. array('parent_id', 'numerical', 'integerOnly'=>true),
  40. array('title', 'length', 'max'=>100),
  41. // The following rule is used by search().
  42. // Please remove those attributes that should not be searched.
  43. array('id, title, parent_id', 'safe', 'on'=>'search'),
  44. );
  45. }
  46.  
  47. /**
  48. * @return array relational rules.
  49. */
  50. public function relations()
  51. {
  52. // NOTE: you may need to adjust the relation name and the related
  53. // class name for the relations automatically generated below.
  54. return array(
  55. 'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
  56. 'products'=>array(self::MANY_MANY, 'Products',
  57. 'prod_to_cats(category_id, product_id)'),
  58. );
  59. }
  60.  
  61. /**
  62. * @return array customized attribute labels (name=>label)
  63. */
  64. public function attributeLabels()
  65. {
  66. return array(
  67. 'id' => 'ID',
  68. 'title' => 'Τίτλος',
  69. 'parent_id' => 'Συγκένεια',
  70. );
  71. }
  72.  
  73. /**
  74. * Retrieves a list of models based on the current search/filter conditions.
  75. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  76. */
  77. public function search()
  78. {
  79. // Warning: Please modify the following code to remove attributes that
  80. // should not be searched.
  81.  
  82. $criteria=new CDbCriteria;
  83.  
  84. $criteria->compare('id',$this->id);
  85. $criteria->compare('title',$this->title,true);
  86. $criteria->compare('parent_id',$this->parent_id);
  87.  
  88. return new CActiveDataProvider(get_class($this), array(
  89. 'criteria'=>$criteria,
  90. ));
  91. }
  92. }
Add Comment
Please, Sign In to add comment