/** * Updates an existing News 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); if ($model->load(Yii::$app->request->post())) { $oldName = $model->getOldAttributes()['name']; $file = UploadedFile::getInstance($model, 'image_id'); if ($file !== null) { $img = Image::saveByFile($file); $model->image_id = $img === null ? $model->getOldProperties()['image_id'] : $img->id; } $models = []; if ($model->name !== $oldName) { $models = array_merge(Page::find()->where(['name' => $oldName])->all(), [$model]); } else { $models = Page::find()->where(['name' => $model->name])->all(); } foreach ($models as $m) { $m->name = $model->name; $m->image_id = $model->image_id; $m->save(); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }