/**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Products::find()->with(
            'category0',
            'brand0'
        );

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        //dump($this);

        $dataProvider->pagination->pageSize=$this->pageSize;
        $dataProvider->key='product_id';

        $query->andFilterWhere([
            'cat_id' => ($this->category) ? intval($this->category) : '',
            'brand_id' => ($this->brand) ? intval($this->brand) : '',
        ]);

        $query->andFilterWhere(['like', 'name', $this->name]);

        return $dataProvider;
    }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Products::className(), ['lot' => 'id']);
 }
 /**
  * Finds the Products model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $_id
  * @return Products the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Products::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }