Exemple #1
0
 public function addCategory()
 {
     if ($this->validate()) {
         $category = new Categories();
         $category->name = $this->name;
         $category->slug = $this->slug;
         if (Yii::$app->request->post('cats') == 0 && $category->makeRoot()) {
             return $category;
         } else {
             $parent = Categories::findOne(['id' => Yii::$app->request->post('cats')]);
             $category->makeRoot();
             $category->appendTo($parent);
             return $category;
         }
     }
     return null;
 }