示例#1
0
 public function actionUpdate($id)
 {
     // Find Model
     $model = MenuService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $model->setScenario('update');
         $pages = PageService::getIdNameList();
         $links = MenuService::getLinks($model);
         $pageLinks = MenuService::getPageLinksForUpdate($model, $pages);
         if ($model->load(Yii::$app->request->post(), 'ObjectData') && Link::loadMultiple($links, Yii::$app->request->post(), 'Link') && PageLink::loadMultiple($pageLinks, Yii::$app->request->post(), 'PageLink') && $model->validate() && Link::validateMultiple($links) && PageLink::validateMultiple($pageLinks)) {
             if (MenuService::update($model)) {
                 MenuService::updateLinks($model, $links, $pageLinks);
                 $this->redirect(['all']);
             }
         }
         return $this->render('update', ['model' => $model, 'links' => $links, 'pageLinks' => $pageLinks]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }