Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'pid' => $this->pid, 'level' => $this->level, 'cover' => $this->cover, 'sort' => $this->sort, 'is_leaf' => $this->is_leaf, 'created_at' => $this->created_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_description', $this->seo_description]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }