/** * Updates an existing Producto 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); $categoria = new Categoria(); $categoriasActivas = $categoria->getCategoriasActivas(); if ($model->load(Yii::$app->request->post())) { $subioArchivo = false; if ($model->file = UploadedFile::getInstance($model, 'file')) { $subioArchivo = true; $nombreImagen = $model->nombre; $model->imagen = 'img/' . $nombreImagen . '.' . $model->file->extension; } if ($model->validate()) { $model->save(); if ($subioArchivo) { $model->file->saveAs('img/' . $model->nombre . '.' . $model->file->extension); } Yii::$app->getSession()->setFlash('success', Yii::t('core', 'Product has been succesfully updated')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categorias' => $categoriasActivas]); } } else { return $this->render('update', ['model' => $model, 'categorias' => $categoriasActivas]); } }