/** * Main menu item creation * @return boolean */ public function create($parent_id) { if (!$this->validate()) { return false; } $parent = Menu::findOne($parent_id); if ($parent === null) { $parent = Menu::find()->roots()->one(); } if ($parent === null) { return false; } $this->item = new Menu(); $this->item->setAttributes(['name' => $this->name, 'active' => $this->active, 'type' => $this->type, 'url' => $this->url, 'alias' => $this->alias], false); $success = $this->item->appendTo($parent, false); return $success; }
public function actionMove($id, $target, $position) { $item = Menu::findOne($id); if ($item === null) { throw new BadRequestHttpException(Yii::t('menu', 'Menu item not found.')); } $t = Menu::findOne($target); if ($t === null) { throw new BadRequestHttpException(Yii::t('menu', 'Menu item not found.')); } switch ($position) { case 0: $item->insertBefore($t); break; case 1: $item->appendTo($t); break; case 2: $item->insertAfter($t); break; } }