コード例 #1
0
ファイル: PageController.php プロジェクト: Zlatov/yii2test
 /**
  * Updates an existing Page model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $pageList = Page::find()->select(['id', 'header', 'pid'])->where(['not', ['id' => $id]])->asArray()->all();
     $pageList = Tree::header($pageList);
     array_unshift($pageList, ['id' => '0', 'header' => 'Эта страница будет корневой', 'pid' => null, 'level' => 0]);
     $pageList = ArrayHelper::map($pageList, 'id', 'header');
     $paramsPageList = ['encode' => false, 'size' => 20];
     if (is_null($model->pid)) {
         $model->pid = '0';
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'pageList' => $pageList, 'paramsPageList' => $paramsPageList]);
     }
 }