/** * Lists all Category models. * @return mixed */ public function actionIndex($type) { /* $searchModel = new CategorySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); */ $query = Category::find(); $query->where(['type' => $type]); $dataProvider = $this->getDataProvider($query); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'sort_num' => $this->sort_num]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }