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