/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Faq::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('faqType'); $query->andFilterWhere(['faq_id' => $this->faq_id]); $query->andFilterWhere(['like', 'question', $this->question])->andFilterWhere(['like', 'answer', $this->answer])->andFilterWhere(['like', 'faqtype.type', $this->faq_type_id]); return $dataProvider; }
public function search($params) { $query = Faq::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['defaultOrder' => ['faq_weight' => SORT_ASC], 'attributes' => ['id', 'faq_question' => ['asc' => ['faq.faq_question' => SORT_ASC], 'desc' => ['faq.faq_question' => SORT_DESC], 'label' => 'Вопрос'], 'faq_answer' => ['asc' => ['faq.faq_answer' => SORT_ASC], 'desc' => ['faq.faq_answer' => SORT_DESC], 'label' => 'Ответ'], 'faqCategoryName' => ['asc' => ['faq_category.faq_category_name' => SORT_ASC], 'desc' => ['faq_category.faq_category_name' => SORT_DESC], 'label' => 'Категория'], 'faq_weight' => ['asc' => ['faq.faq_weight' => SORT_ASC], 'desc' => ['faq.faq_weight' => SORT_DESC], 'label' => 'Приоритет от 1 до 100'], 'faqIsFeaturedName' => ['asc' => ['faq.faq_is_featured' => SORT_ASC], 'desc' => ['faq.faq_is_featured' => SORT_DESC], 'label' => 'Опубликовано?']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['faqCategory']); return $dataProvider; } $this->addSearchParameter($query, 'id'); $this->addSearchParameter($query, 'faq_category_id'); $this->addSearchParameter($query, 'faq_weight'); $this->addSearchParameter($query, 'faq_is_featured'); $this->addSearchParameter($query, 'created_by'); $this->addSearchParameter($query, 'updated_by'); $this->addSearchParameter($query, 'faq_question', true); $this->addSearchParameter($query, 'faq_answer', true); $query->joinWith(['faqCategory' => function ($q) { $q->andFilterWhere(['=', 'faq_category.faq_category_name', $this->faqCategoryName]); }]); return $dataProvider; }