コード例 #1
0
 public function init()
 {
     parent::init();
     $this->error_code = 0;
     // Проверка наличия в базе категории с заданим id
     $this->categories = Categories::find()->where(['id' => $this->cat_id])->one();
     if (!$this->categories) {
         if (!$this->cat_id) {
             //Виборка всех статей сортю по дате в одратном порядке
             $this->articles = Articles::find()->orderBy(['date' => SORT_DESC])->all();
             //.. проверка успешности операции
             if (!$this->articles) {
                 $this->error_code = 2;
             }
         } else {
             $this->error_code = 1;
         }
     } else {
         //Запись названия категории
         $this->cat_name = Html::encode($this->categories->title);
         //Виборка всех статей категории сорт. по дате в одратном порядке
         $this->articles = Articles::find()->where(['cat' => $this->cat_id])->orderBy(['date' => SORT_DESC])->all();
         //.. проверка успешности операции
         if (!$this->articles) {
             $this->error_code = 2;
         }
     }
 }
コード例 #2
0
 /**
  * Finds the Articles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Articles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findArticleModel($id)
 {
     if (($model = Articles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Articles::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, 'date' => $this->date, 'cat' => $this->cat, 'author' => $this->author, 'slider' => $this->slider, 'video' => $this->video]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'img', $this->img])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
コード例 #4
0
 public function init()
 {
     parent::init();
     $this->error_code = 0;
     // Проверка наличия в базе категории с заданим id
     $this->articles = Articles::find()->where(['id' => $this->art_id])->one();
     $this->categories = Categories::find()->where(['id' => $this->articles->cat])->one();
     if (!$this->articles) {
         $this->error_code = 3;
     }
     if (!$this->categories) {
         $this->error_code = 4;
     }
 }