示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SiteNews::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, 'views' => $this->views, 'status' => $this->status, 'create_at' => $this->create_at, 'update_at' => $this->update_at, 'create_by' => $this->create_by, 'update_by' => $this->update_by, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'thump', $this->thump])->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
示例#2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSiteNews()
 {
     return $this->hasMany(SiteNews::className(), ['category_id' => 'id']);
 }
示例#3
0
 /**
  * Finds the SiteNews model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SiteNews the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SiteNews::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }