/** * 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]); $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, 'post_author' => $this->post_author, 'post_date' => $this->post_date, 'post_date_gmt' => $this->post_date_gmt, 'post_modified' => $this->post_modified, 'post_modified_gmt' => $this->post_modified_gmt, 'post_parent' => $this->post_parent, 'menu_order' => $this->menu_order, 'comment_count' => $this->comment_count]); $query->andFilterWhere(['like', 'post_content', $this->post_content])->andFilterWhere(['like', 'post_title', $this->post_title])->andFilterWhere(['like', 'post_excerpt', $this->post_excerpt])->andFilterWhere(['like', 'post_status', $this->post_status])->andFilterWhere(['like', 'comment_status', $this->comment_status])->andFilterWhere(['like', 'ping_status', $this->ping_status])->andFilterWhere(['like', 'post_password', $this->post_password])->andFilterWhere(['like', 'post_name', $this->post_name])->andFilterWhere(['like', 'to_ping', $this->to_ping])->andFilterWhere(['like', 'pinged', $this->pinged])->andFilterWhere(['like', 'post_content_filtered', $this->post_content_filtered])->andFilterWhere(['like', 'guid', $this->guid])->andFilterWhere(['like', 'post_type', $this->post_type]); 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 string $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.'); } }