You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.0 KiB

  1. <?php
  2. namespace common\models;
  3. use yii\base\Model;
  4. use yii\data\ActiveDataProvider;
  5. use common\models\Category;
  6. /**
  7. * CategorySearch represents the model behind the search form of `\common\models\Category`.
  8. */
  9. class CategorySearch extends Category {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function rules() {
  14. return [
  15. [['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'],
  16. [['cat_name', 'icon', 'description'], 'safe'],
  17. ];
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function scenarios() {
  23. // bypass scenarios() implementation in the parent class
  24. return Model::scenarios();
  25. }
  26. /**
  27. * Creates data provider instance with search query applied
  28. *
  29. * @param array $params
  30. *
  31. * @return ActiveDataProvider
  32. */
  33. public function search($params) {
  34. $query = Category::find();
  35. // add conditions that should always apply here
  36. $dataProvider = new ActiveDataProvider([
  37. 'query' => $query,
  38. 'pagination' => [
  39. 'pageSizeLimit' => [1, 200]
  40. ],
  41. 'sort' => [
  42. 'defaultOrder' => [
  43. 'id' => SORT_DESC,
  44. ]
  45. ],
  46. ]);
  47. $this->load($params);
  48. if (!$this->validate()) {
  49. // uncomment the following line if you do not want to return any records when validation fails
  50. // $query->where('0=1');
  51. return $dataProvider;
  52. }
  53. // grid filtering conditions
  54. $query->andFilterWhere([
  55. 'id' => $this->id,
  56. 'icon_type' => $this->icon_type,
  57. 'sort_order' => $this->sort_order,
  58. 'created_at' => $this->created_at,
  59. 'updated_at' => $this->updated_at,
  60. ]);
  61. $query->andFilterWhere(['like', 'cat_name', $this->cat_name])
  62. ->andFilterWhere(['like', 'icon', $this->icon])
  63. ->andFilterWhere(['like', 'description', $this->description]);
  64. return $dataProvider;
  65. }
  66. }