/** * 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; }
/** * Finds the Posts model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Posts the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Posts::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }