/** * Lists all Article models. * @return mixed */ public function actionIndex() { if (!\Yii::$app->user->can('articles.view')) { $this->accessDenied(); } $dataProvider = new ActiveDataProvider(['query' => Article::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Displays a single Category model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); return $this->render('view', ['model' => $model, 'categories' => new \yii\data\ArrayDataProvider(['allModels' => $model->children(1)->checkRoot(Yii::$app->settings->get('articles.root'))->all()]), 'articles' => new ActiveDataProvider(['query' => \simplator\articles\models\Article::find()->where(['parentid' => $model->id])->orderBy(['updated_at' => SORT_DESC])])]); }
/** * 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(); } }