Пример #1
0
 /**
  * Displays a single Category model.
  * @param integer $id
  * @return mixed
  */
 public function actionCategory($id)
 {
     $model = Category::find()->where(['id' => $id, 'root' => $this->_rootid])->one();
     if (!$model) {
         throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.'));
     }
     return $this->render('category', ['model' => $model, 'categories' => new ActiveDataProvider(['query' => $model->children(1)]), 'articles' => new ActiveDataProvider(['query' => $model->getArticles(Article::STATUS_RELEASE)])]);
 }
Пример #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.');
     }
 }
Пример #3
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::find()->where(['id' => $id])->checkRoot(Yii::$app->settings->get('articles.root'))->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #4
0
 public function getParent()
 {
     return $this->hasOne(Category::className(), ['id' => 'parentid']);
 }
Пример #5
0
 /**
  * Check pathes
  * @param integer $limit 
  */
 public static function checkPathes($limit = 0)
 {
     $module = \Yii::$app->getModule('articles');
     $count = Category::find()->count();
     if ($count < 1) {
         $category = new Category();
         $category->title = $module->title;
         $category->name = $module->id;
         $category->genPath();
         $category->makeRoot();
         \Yii::$app->settings->set('articles.root', $category->id);
     }
     $categories = Category::find()->where(['path' => NULL])->all();
     foreach ($categories as $category) {
         $category->scenario = 'check';
         $category->save();
     }
     $articles = Article::find()->where(['path' => NULL])->all();
     foreach ($articles as $article) {
         $article->save();
     }
 }