public static function getMenuById($id) { if ($id != NULL) { $name = Menu::findOne($id); return $name->nombre; } return "No Asignado"; }
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('转移失败'); } }
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); }
/** * 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.')); } }