/** * Updates an existing Productos 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); $img_model = new UploadForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $request = Yii::$app->request; $id_producto = $model->id; $fotos = Fotos::find()->where(['idProducto' => $id_producto])->all(); foreach ($fotos as $foto) { Fotos::deleteFoto($foto); } $img_model->imageFiles = UploadedFile::getInstances($img_model, 'imageFiles'); if ($img_model->upload($model->id)) { if ($model->tipo == 0) { return $this->redirect(['view', 'id' => $model->id]); } else { if ($model->tipo == 1) { $porTiempo = Temporales::find()->where(['idproducto' => $model->id])->one(); $porTiempo->fecha = $request->post('fecha'); $porTiempo->idproducto = $model->id; $porTiempo->save(); return $this->redirect(['view', 'id' => $model->id]); } else { $stock = Stock::find()->where(['idproducto' => $model->id])->one(); $cantidad = $request->post('cant'); $stock->stock = $cantidad; $stock->idproducto = $model->id; $stock->save(); return $this->redirect(['view', 'id' => $model->id]); } } } } else { return $this->render('update', ['model' => $model, 'img_model' => $img_model]); } }