/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($p = null) { $parent = $p; $model = new Category(); $data = Yii::$app->request->post(); if ($model->load($data)) { $res = null; if (isset($data['Category']['parentid'])) { $parent = $data['Category']['parentid']; } $parent = Category::findOne(intval($parent)); if ($parent) { $res = $model->appendTo($parent); } else { $res = $model->makeRoot(); } Module::checkPathes(); if ($res) { return $this->redirect(['view', 'id' => $model->id]); } } else { $model->parentid = intval($parent); 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($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]); } }