/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CategoryTag::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); 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; } $query->joinWith(['category', 'tag']); /*$query->andFilterWhere([ 'category_id' => $this->category_id, 'tag_id' => $this->tag_id, ]);*/ $query->andFilterWhere(['like', 'category_name', $this->category_id])->andFilterWhere(['like', 'tag_name', $this->tag_id]); return $dataProvider; }
/** * Finds the CategoryTag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $category_id * @param integer $tag_id * @return CategoryTag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($category_id, $tag_id) { if (($model = CategoryTag::findOne(['category_id' => $category_id, 'tag_id' => $tag_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }