$query, 'pagination' => false, 'sort' => false ]); $this->load($params); return $this->filter($query, $dataProvider); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSizeLimit' => [1, 200] ], 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC, ] ], ]); $this->load($params); return $this->filter($query, $dataProvider); } /** * @param $query * @param $dataProvider * @return ActiveDataProvider * 条件筛选 */ private function filter($query, $dataProvider) { if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'icon_type' => $this->icon_type, 'sort_order' => $this->sort_order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'cat_name', $this->cat_name]) ->andFilterWhere(['like', 'icon', $this->icon]) ->andFilterWhere(['like', 'description', $this->description]); if ($this->created_at_range) { $arr = explode(' ~ ', $this->created_at_range); $start = strtotime($arr[0]); $end = strtotime($arr[1]) + 3600 * 24; $query->andFilterWhere(['between', 'created_at', $start, $end]); } return $dataProvider; } }