/** * Updates an existing Ad model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { if (!$this->is_access('ads/update')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { // 类型为 0:图片;1:Flash时 if ($model->media_type == 0 || $model->media_type == 1) { /* 处理上传的图片 */ if ($_FILES['Ad']['error']['ad_file'] === 0) { /* 把文件的路劲赋值给image字段 */ $model->ad_code = File::uploadImage($model, 'ad_file', 'other'); } } if ($model->save()) { Yii::$app->session->setFlash('success', '编辑成功'); } return $this->redirect(['index']); } else { $AdPosition = new AdPosition(); Yii::$app->view->params['meta_title'] = '编辑广告'; $mediaList = $model->media_type_list(); $position = $AdPosition->ad_position(); return $this->render('update', ['model' => $model, 'mediaList' => $mediaList, 'position' => $position]); } }