/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($category) { $model = new Menu(); $model->category_id = $category; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'category' => $category]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $this->setMenus(29, "添加新菜单"); $model = new Menu(); $id = LsYii::getGetValue('id', null); if ($id) { $model->pid = $id; } if ($model->load(LsYii::getRequest()->post())) { $pid = $model->pid; if ($pid) { $c = Menu::findOne(['`id`' => $pid]); $rgt = $c->rgt; $model->root = $c->root; $model->pid = $c->id; $model->level = $c->level + 1; $model->lft = $rgt; $model->rgt = $rgt + 1; } else { $maxRgt = Menu::getMaxRgt(); $model->lft = $maxRgt + 1; $model->rgt = $maxRgt + 2; $model->pid = 0; $model->level = 1; } if ($model->save()) { if (!$pid) { $menu = Menu::findOne(['`id`' => $model->id]); $menu->root = $model->id; $menu->save(); } else { Menu::updateAllCounters(['rgt' => 2], "`lft`<{$rgt} AND `rgt`>={$rgt}"); Menu::updateAllCounters(['rgt' => 2, 'lft' => 2], "`lft`>{$rgt}"); } } return $this->redirect(['index']); } else { $model->if_show = \source\libs\Constants::Menu_Status_Show; return $this->render('create', ['model' => $model]); } }