/** * Updates an existing Raptor 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); $image = new File(); if (Yii::$app->request->isPost) { // Raptor Form if (Yii::$app->request->post('Raptor')) { if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', '<b>' . $model->species_long . '</b> was updated successfully.'); 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 $raptorImage = new RaptorImage(); $raptorImage->file_id = $image->id; $raptorImage->raptor_id = $id; $raptorImage->save(); Yii::$app->session->setFlash('success', 'The image for <b>' . $model->species_long . '</b> 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' => '']); } } return $this->render('update', ['model' => $model, 'image' => $image]); }