/** * Updates an existing Reporte 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); $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles'); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles'); foreach ($model->imageFiles as $file) { $losArchivos = new ArchivoReporte(); $losArchivos->archivo = 'archivos_reportes/' . $model->id . '_' . $file->baseName . '.' . $file->extension; $losArchivos->reporte_id = $model->id; if ($losArchivos->save()) { $file->saveAs('archivos_reportes/' . $model->id . '_' . $file->baseName . '.' . $file->extension); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }