/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'full_image' => $this->full_image, 'user_created' => $this->user_created, 'user_last_change' => $this->user_last_change, 'publish' => $this->publish]); if ($this->created_at) { $date_cr = date('d-m-Y', (double) $this->created_at); } else { $date_cr = ''; } if ($this->updated_at) { $date_up = date('d-m-Y', (double) $this->updated_at); } else { $date_up = ''; } if ($this->category) { $categoryArray = explode(",", $this->category); $query->andFilterWhere(['in', 'category', $categoryArray]); } $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'intro_text', $this->intro_text])->andFilterWhere(['like', 'full_text', $this->full_text])->andFilterWhere(['like', 'intro_image', $this->intro_image])->andFilterWhere(['like', "date_format(date(from_unixtime(created_at)) ,'%d-%m-%Y' )", $date_cr])->andFilterWhere(['like', "date_format(date(from_unixtime(updated_at)) ,'%d-%m-%Y' )", $date_up]); return $dataProvider; }
public function actionTagslist() { if (\Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $items = Posts::find()->select(['tags'])->andHaving(['!=', 'tags', ''])->orderBy(['tags' => SORT_ASC])->all(); $resp_items = []; $temp_items = []; foreach ($items as $item) { $newItems = explode(",", $item['tags']); foreach ($newItems as $newItem) { $temp_items[] = $newItem; } } // make unique values $temp_items = array_unique($temp_items); foreach ($temp_items as $item) { $resp_items[]["tags"] = $item; } return $resp_items; } else { } }