/** * 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)])]); }
/** * 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.'); } }
/** * Lists all Category models. * @return mixed */ public function actionIndex() { return $this->actionView($this->_rootid); $dataProvider = new ActiveDataProvider(['query' => Category::find()->roots()]); return $this->render('index', ['categories' => $dataProvider]); }
/** * 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(); } }