コード例 #1
0
 public function actionCreate($parent_id)
 {
     $model = new Category();
     $model->parent_id = $parent_id;
     if ($parent_id == 0) {
         $parent = new Home();
     } else {
         $parent = Category::findOne($parent_id);
         if (is_null($parent)) {
             throw new \yii\web\HttpException(404, Yii::t('burivuh', 'The category does not exist'));
         }
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->redirect($model->url);
     }
     return $this->render('create', ['model' => $model, 'parent' => $parent]);
 }