Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductModel::find();
     $query->with(['category', 'group']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'group_id' => $this->group_id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public function actionProductList($term = '')
 {
     $response = Yii::$app->response;
     $response->format = 'json';
     return Product::find()->filterWhere(['like', 'lower([[name]])', strtolower($term)])->orFilterWhere(['like', 'lower([[name]])', strtolower($term)])->limit(10)->asArray()->all();
 }