Commit b1f73dd70ead14497065262043052edbb15b2286
Merge remote-tracking branch 'origin/master'
Showing
2 changed files
with
8 additions
and
10 deletions
Show diff stats
common/models/Customer.php
| @@ -109,7 +109,6 @@ | @@ -109,7 +109,6 @@ | ||
| 109 | 'citizenship', | 109 | 'citizenship', |
| 110 | 'passport', | 110 | 'passport', |
| 111 | 'email', | 111 | 'email', |
| 112 | - 'image', | ||
| 113 | ], | 112 | ], |
| 114 | 'required', | 113 | 'required', |
| 115 | ], | 114 | ], |
| @@ -145,20 +144,19 @@ | @@ -145,20 +144,19 @@ | ||
| 145 | } | 144 | } |
| 146 | 145 | ||
| 147 | 146 | ||
| 148 | - public function upload($file) | 147 | + public function upload() |
| 149 | { | 148 | { |
| 150 | /** | 149 | /** |
| 151 | * @var \yii\web\UploadedFile $file; | 150 | * @var \yii\web\UploadedFile $file; |
| 152 | */ | 151 | */ |
| 153 | - $this->file = $file; | ||
| 154 | - if (!empty($file)) { | 152 | + if (!empty($this->file) and $this->validate()) { |
| 155 | if (!file_exists(\Yii::getAlias('@storage/customers/'))) { | 153 | if (!file_exists(\Yii::getAlias('@storage/customers/'))) { |
| 156 | FileHelper::createDirectory(\Yii::getAlias('@storage/customers/')); | 154 | FileHelper::createDirectory(\Yii::getAlias('@storage/customers/')); |
| 157 | } | 155 | } |
| 158 | - | ||
| 159 | - if ($file->saveAs(\Yii::getAlias('@storage/customers/') . $file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension)) { | ||
| 160 | - $this->image = '/storage/customers/'.$file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension; | ||
| 161 | - $this->file->name = $file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension;; | 156 | + $filename = $this->file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$this->file->extension; |
| 157 | + if ($this->file->saveAs(\Yii::getAlias('@storage/customers/') . $filename)) { | ||
| 158 | + $this->image = '/storage/customers/'.$filename; | ||
| 159 | + $this->file->name = $filename; | ||
| 162 | return true; | 160 | return true; |
| 163 | } | 161 | } |
| 164 | return false; | 162 | return false; |
frontend/controllers/SiteController.php
| @@ -155,8 +155,8 @@ | @@ -155,8 +155,8 @@ | ||
| 155 | { | 155 | { |
| 156 | $model = new Customer(); | 156 | $model = new Customer(); |
| 157 | if ($model->load(\Yii::$app->request->post())){ | 157 | if ($model->load(\Yii::$app->request->post())){ |
| 158 | - | ||
| 159 | - if ($model->upload(UploadedFile::getInstance($model, 'file')) and $model->save()){ | 158 | + $model->file = UploadedFile::getInstance($model, 'file'); |
| 159 | + if ($model->upload() and $model->save()){ | ||
| 160 | \Yii::$app->session->setFlash('success', \Yii::t('app', 'Дякуемо за реєстрацію. Підтвердження участі буде відправлено на вказаний email')); | 160 | \Yii::$app->session->setFlash('success', \Yii::t('app', 'Дякуемо за реєстрацію. Підтвердження участі буде відправлено на вказаний email')); |
| 161 | return $this->redirect(['site/index']); | 161 | return $this->redirect(['site/index']); |
| 162 | } | 162 | } |