예제 #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;
 }
예제 #2
0
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }