/** * Updates an existing Ad model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $oldimg = $model->img; if ($model->load(Yii::$app->request->post())) { $img = UploadedFile::getInstance($model, 'img'); if ($img) { $file = 'upload/' . time() . mt_rand(1, 999) . '.' . $img->extension; $img->saveAs($file); $model->img = $file; } else { $model->img = $oldimg; } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { $adverlist = Adver::getDropList(); return $this->render('update', ['model' => $model, 'adverlist' => $adverlist]); } }