/** * Updates an existing Incident model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $incident = $this->findModel($id); $image = new File(); $prey = new Prey(); if (Yii::$app->request->isPost) { // Incident Form if (Yii::$app->request->post('Incident')) { if ($incident->load(Yii::$app->request->post()) && $incident->save()) { Yii::$app->session->setFlash('success', 'The incident was successfully updated.'); return $this->redirect(['update', 'id' => $id]); } } // File Form if (Yii::$app->request->post('File')) { $image->file = UploadedFile::getInstance($image, 'file'); if ($image->uploadFile()) { // file is uploaded successfully $incidentImage = new IncidentImage(); $incidentImage->file_id = $image->id; $incidentImage->incident_id = $id; $incidentImage->save(); Yii::$app->session->setFlash('success', 'The image was successfully uploaded.'); return $this->redirect(['update', 'id' => $id, 'photoID' => '']); } Yii::$app->session->setFlash('danger', 'Something went wrong.'); return $this->redirect(['update', 'id' => $id, 'photoID' => '']); } // Prey Form if (Yii::$app->request->post('Prey')) { if ($prey->load(Yii::$app->request->post())) { $prey->incident_id = $incident->id; $prey->raptor_id = $incident->raptor_id; if ($prey->save()) { Yii::$app->session->setFlash('success', 'Prey for raptor <b>' . $incident->raptor->species_long . '</b> was successfully created.'); return $this->redirect(['update', 'id' => $id, 'preyID' => '']); } Yii::$app->session->setFlash('danger', 'Something went wrong.'); return $this->redirect(['update', 'id' => $id, 'preyID' => '']); } } } return $this->render('update', ['incident' => $incident, 'image' => $image, 'prey' => $prey]); }