예제 #1
0
 public static function getMenuById($id)
 {
     if ($id != NULL) {
         $name = Menu::findOne($id);
         return $name->nombre;
     }
     return "No Asignado";
 }
예제 #2
0
 public function actionNodeDrop($id)
 {
     $model = Menu::findOne($id);
     $model->attributes = Yii::$app->request->get();
     if (Yii::$app->request->get('movetype') == 'inner') {
     }
     if ($model->save()) {
         return $this->ok('转移成功');
     } else {
         return $this->error('转移失败');
     }
 }
예제 #3
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $model = new Menu();
     if (!empty($this->id)) {
         $model = Menu::findOne($this->id);
     }
     $model->setAttributes(['name' => $this->name, 'alias' => $this->alias]);
     $isNew = $model->isNewRecord;
     if ($model->save(false)) {
         $this->id = $model->id;
         if (!$isNew) {
             $oldItems = MenuItem::find()->where(['menuID' => $this->id])->all();
             $existedMenus = ArrayHelper::getColumn($oldItems, 'id');
             $newItems = ArrayHelper::getColumn($this->items, 'id');
             if ($needToRemoveItems = array_diff($existedMenus, $newItems)) {
                 \Yii::trace($needToRemoveItems);
                 foreach ($oldItems as $item) {
                     if (in_array($item->id, $needToRemoveItems)) {
                         $item->delete();
                     }
                 }
             }
         }
         foreach ($this->items as $order => $menuItem) {
             if (!$menuItem->menuID) {
                 $menuItem->menuID = $this->id;
             }
             if (!$menuItem->order) {
                 $menuItem->order = $order;
             }
             $menuItem->save();
         }
     }
     return !empty($this->id);
 }
예제 #4
0
 /**
  * Finds the Menu model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Menu the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Menu::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }