Example #1
0
 /**
  * Updates an existing Item 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);
     if ($model->load(Yii::$app->request->post())) {
         $model->url = UrlHelp::translateUrl($model->url);
         $model->price = Item::toTen($model->price);
         $model->absorption = Item::toTen($model->absorption);
         if ($model->validate()) {
             $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
             if ($model->imageFile) {
                 if ($imgName = $model->upload($model->url)) {
                     $model->img = $imgName;
                 }
             }
             $model->imageFile = null;
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('update', ['model' => $model]);
 }