public function search($params) { $query = Products::find()->joinWith(['characteristics']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['id' => SORT_ASC, 'clk_name' => SORT_ASC, 'characteristics.display_type' => SORT_ASC, 'characteristics.mechanism_type' => SORT_ASC, 'characteristics.starp_type' => SORT_ASC], 'attributes' => ['id', 'clk_name', 'characteristics.display_type', 'characteristics.starp_type', 'characteristics.mechanism_type']], 'key' => 'id']); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['products.id' => $this->id])->andFilterWhere(['like', 'clk_name', $this->clk_name])->andFilterWhere(['like', 'clk_description', $this->clk_description])->andFilterWhere(['like', 'characteristics.display_type', $this->getAttribute('characteristics.display_type')])->andFilterWhere(['like', 'characteristics.mechanism_type', $this->getAttribute('characteristics.mechanism_type')])->andFilterWhere(['like', 'characteristics.starp_type', $this->getAttribute('characteristics.starp_type')]); return $dataProvider; }
public function fillInTheRest() { $product = Products::find()->with(['characteristics'])->where(['id' => $this->id])->one(); if (!$product) { throw new NotFoundHttpException('Product Not Found'); } $this->name = $product->clk_name; $this->description = $product->clk_description; $this->displayType = $product->characteristics->display_type; $this->mechanismType = $product->characteristics->mechanism_type; $this->starpType = $product->characteristics->starp_type; $this->sex = $product->characteristics->sex; $this->price = $product->price; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Products::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->andFilterWhere(['id' => $this->id, 'section_id' => $this->section_id, 'price' => $this->price, 'sensitivity' => $this->sensitivity, 'connector' => $this->connector, 'length' => $this->length, 'date' => $this->date]); $query->andFilterWhere(['like', 'img', $this->img])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'acoustic', $this->acoustic])->andFilterWhere(['like', 'frequency', $this->frequency]); return $dataProvider; }
public function actionCatalog() { $query = Products::find()->joinWith(['images', 'characteristics']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 4], 'sort' => ['attributes' => ['price' => ['label' => 'Цене'], 'clk_name' => ['label' => 'Названию']]]]); return $this->render('catalog', ['dataProvider' => $dataProvider]); }