Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::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, 'cat_id' => $this->cat_id, 'is_open' => $this->is_open, 'is_recommend' => $this->is_recommend, 'sort_order' => $this->sort_order, 'type' => $this->type, 'is_hot' => $this->is_hot]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'min_title', $this->min_title])->andFilterWhere(['like', 'pub_time', $this->pub_time])->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at])->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'images', $this->images])->andFilterWhere(['like', 'ext_data', $this->ext_data]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * Finds the Article model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Article the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }