Ejemplo n.º 1
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($parentid)
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save() && $model->setParent($parentid)) {
         Yii::$app->settings->default->flushSettings();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
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();
     }
 }