| @@ 14-96 (lines=83) @@ | ||
| 11 | * |
|
| 12 | * @package app\models |
|
| 13 | */ |
|
| 14 | class CategorySearch extends Category |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @inheritdoc |
|
| 18 | */ |
|
| 19 | public function rules() |
|
| 20 | { |
|
| 21 | return [ |
|
| 22 | [ |
|
| 23 | ['id'], |
|
| 24 | 'integer', |
|
| 25 | ], |
|
| 26 | [ |
|
| 27 | [ |
|
| 28 | 'title', |
|
| 29 | 'description' |
|
| 30 | ], |
|
| 31 | 'string', |
|
| 32 | ], |
|
| 33 | [ |
|
| 34 | [ |
|
| 35 | 'created_at', |
|
| 36 | 'updated_at', |
|
| 37 | ], |
|
| 38 | 'safe', |
|
| 39 | ], |
|
| 40 | ]; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @inheritdoc |
|
| 45 | */ |
|
| 46 | public function scenarios() |
|
| 47 | { |
|
| 48 | // bypass scenarios() implementation in the parent class |
|
| 49 | return Model::scenarios(); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Creates data provider instance with search query applied |
|
| 54 | * |
|
| 55 | * @param array $params |
|
| 56 | * |
|
| 57 | * @return ActiveDataProvider |
|
| 58 | */ |
|
| 59 | public function search($params) |
|
| 60 | { |
|
| 61 | $query = Category::find(); |
|
| 62 | ||
| 63 | // add conditions that should always apply here |
|
| 64 | ||
| 65 | $dataProvider = new ActiveDataProvider([ |
|
| 66 | 'query' => $query, |
|
| 67 | ]); |
|
| 68 | ||
| 69 | $this->load($params); |
|
| 70 | ||
| 71 | if (!$this->validate()) { |
|
| 72 | // uncomment the following line if you do not want to return any records when validation fails |
|
| 73 | // $query->where('0=1'); |
|
| 74 | return $dataProvider; |
|
| 75 | } |
|
| 76 | ||
| 77 | // grid filtering conditions |
|
| 78 | $query->andFilterWhere([ |
|
| 79 | 'id' => $this->id, |
|
| 80 | 'created_at' => $this->created_at, |
|
| 81 | 'updated_at' => $this->updated_at, |
|
| 82 | ]); |
|
| 83 | ||
| 84 | $query->andFilterWhere(['like', 'title', $this->title]); |
|
| 85 | $query->andFilterWhere(['like', 'description', $this->description]); |
|
| 86 | ||
| 87 | $pagination = new Pagination([ |
|
| 88 | 'defaultPageSize' => Yii::$app->params['defaultPageSize'], |
|
| 89 | 'totalCount' => $query->count(), |
|
| 90 | ]); |
|
| 91 | ||
| 92 | $dataProvider->setPagination($pagination); |
|
| 93 | ||
| 94 | return $dataProvider; |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||
| @@ 14-96 (lines=83) @@ | ||
| 11 | * |
|
| 12 | * @package app\models |
|
| 13 | */ |
|
| 14 | class PageSearch extends Page |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @inheritdoc |
|
| 18 | */ |
|
| 19 | public function rules() |
|
| 20 | { |
|
| 21 | return [ |
|
| 22 | [ |
|
| 23 | ['id'], |
|
| 24 | 'integer', |
|
| 25 | ], |
|
| 26 | [ |
|
| 27 | [ |
|
| 28 | 'title', |
|
| 29 | 'description' |
|
| 30 | ], |
|
| 31 | 'string', |
|
| 32 | ], |
|
| 33 | [ |
|
| 34 | [ |
|
| 35 | 'created_at', |
|
| 36 | 'updated_at', |
|
| 37 | ], |
|
| 38 | 'safe', |
|
| 39 | ], |
|
| 40 | ]; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @inheritdoc |
|
| 45 | */ |
|
| 46 | public function scenarios() |
|
| 47 | { |
|
| 48 | // bypass scenarios() implementation in the parent class |
|
| 49 | return Model::scenarios(); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Creates data provider instance with search query applied |
|
| 54 | * |
|
| 55 | * @param array $params |
|
| 56 | * |
|
| 57 | * @return ActiveDataProvider |
|
| 58 | */ |
|
| 59 | public function search($params) |
|
| 60 | { |
|
| 61 | $query = Page::find(); |
|
| 62 | ||
| 63 | // add conditions that should always apply here |
|
| 64 | ||
| 65 | $dataProvider = new ActiveDataProvider([ |
|
| 66 | 'query' => $query, |
|
| 67 | ]); |
|
| 68 | ||
| 69 | $this->load($params); |
|
| 70 | ||
| 71 | if (!$this->validate()) { |
|
| 72 | // uncomment the following line if you do not want to return any records when validation fails |
|
| 73 | // $query->where('0=1'); |
|
| 74 | return $dataProvider; |
|
| 75 | } |
|
| 76 | ||
| 77 | // grid filtering conditions |
|
| 78 | $query->andFilterWhere([ |
|
| 79 | 'id' => $this->id, |
|
| 80 | 'created_at' => $this->created_at, |
|
| 81 | 'updated_at' => $this->updated_at, |
|
| 82 | ]); |
|
| 83 | ||
| 84 | $query->andFilterWhere(['like', 'title', $this->title]); |
|
| 85 | $query->andFilterWhere(['like', 'description', $this->description]); |
|
| 86 | ||
| 87 | $pagination = new Pagination([ |
|
| 88 | 'defaultPageSize' => Yii::$app->params['defaultPageSize'], |
|
| 89 | 'totalCount' => $query->count(), |
|
| 90 | ]); |
|
| 91 | ||
| 92 | $dataProvider->setPagination($pagination); |
|
| 93 | ||
| 94 | return $dataProvider; |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||