Пример #1
0
 /**
  * Creates a new Denuncia model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Denuncia();
     $model->idLocal = 0;
     if ($model->load(Yii::$app->request->post())) {
         list($dia, $mes, $ano) = split('[/]', $model->data);
         $model->data = $ano . '-' . $mes . '-' . $dia;
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         $path = Yii::$app->basePath . '/web/uploadFoto/';
         $model->status = 1;
         if ($model->save()) {
             foreach ($model->imageFiles as $file) {
                 $foto = new Foto();
                 $foto->idDenuncia = $model->idDenuncia;
                 $foto->endereco = $path . $file->baseName . '.' . $file->extension;
                 $foto->nome = $file->baseName . '.' . $file->extension;
                 $foto->comentario = $model->comentarioFoto;
                 $file->saveAs($foto->endereco);
                 $foto->save();
                 $foto = null;
             }
             return $this->render('sucesso');
         } else {
             list($ano, $mes, $dia) = split('[-]', $model->data);
             $model->data = $dia . '/' . $mes . '/' . $ano;
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }