public function actionCreate() { $model = new Category(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->parent == 0) { $model->saveNode(); } elseif ($model->parent) { $root = Category::find($model->parent); $model->appendTo($root); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Category(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->parent == 0) { $model->saveNode(); } else { if ($model->parent) { $root = $this->findModel($model->parent); $model->appendTo($root); } } return $this->render('tree'); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Category(); if ($model->load(Yii::$app->request->post())) { $model->url = UrlHelp::translateUrl($model->name); if ($model->validate()) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->imageFile) { if ($imgName = $model->upload($model->url)) { $model->img = $imgName; } } $model->imageFile = null; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }