/** * Search Term through Ajax with JSON as response. * * @return string */ public function actionAjaxSearch() { Yii::$app->response->format = Response::FORMAT_JSON; if ($term = Yii::$app->request->post('Term')) { $model = Term::find()->select(['id', 'name'])->where(['like', 'name', $term['name']])->andWhere(['taxonomy_id' => $term['taxonomy_id']])->limit('10')->all(); if ($model) { return $model; } } return []; }
/** * Creates data provider instance with search query applied * * @param array $params * @param int $taxonomyId * @return ActiveDataProvider */ public function search($params, $taxonomyId) { $query = TermModel::find(); $query->andWhere(['taxonomy_id' => $taxonomyId]); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'taxonomy_id' => $this->taxonomy_id, 'parent' => $this->parent, 'count' => $this->count]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * @param int $taxonomy_id * * @return ActiveDataProvider */ public function search($params, $taxonomy_id) { $query = TermModel::find(); $query->andWhere(['taxonomy_id' => $taxonomy_id]); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'taxonomy_id' => $this->taxonomy_id, 'term_parent' => $this->term_parent, 'term_count' => $this->term_count]); $query->andFilterWhere(['like', 'term_name', $this->term_name])->andFilterWhere(['like', 'term_slug', $this->term_slug])->andFilterWhere(['like', 'term_description', $this->term_description]); return $dataProvider; }
/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param $term_slug * * @throws \yii\web\NotFoundHttpException * @internal param string $post_slug * * @return Term the loaded model */ protected function findModelBySlug($term_slug) { $model = Term::find()->andWhere(['term_slug' => $term_slug])->one(); if ($model) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }