コード例 #1
0
ファイル: ManageController.php プロジェクト: ahb360/cms
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['Page']['parentId'] != '0') {
             $parent = $model->parents(1)->one();
             if (!isset($parent) or $parent->id != $_POST['Page']['parentId']) {
                 $newParent = Page::findOne($_POST['Page']['parentId']);
                 $success = $model->appendTo($newParent);
             } else {
                 $success = $model->save();
             }
         } else {
             $success = $model->isRoot() ? $model->save() : $model->makeRoot();
         }
         if ($success) {
             Yii::$app->session->addFlash('success', 'صفحه ویرایش شده با موفقیت در سیستم به روز رسانی شد.');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('update', ['model' => $model]);
 }