コード例 #1
0
ファイル: MenuForm.php プロジェクト: simple-yii2/menu
 /**
  * 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;
 }
コード例 #2
0
ファイル: MenuController.php プロジェクト: simple-yii2/menu
 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;
     }
 }