示例#1
0
 /**
  * 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]);
 }
 /**
  * Finds the RaptorImage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RaptorImage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RaptorImage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $raptorid)
 {
     $query = RaptorImage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'raptor_id' => $this->raptor_id, 'file_id' => $this->file_id]);
     $query->andWhere(['raptor_id' => $raptorid]);
     return $dataProvider;
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRaptorImages()
 {
     return $this->hasMany(RaptorImage::className(), ['raptor_id' => 'id']);
 }