Guest User

Untitled

a guest
Dec 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public function actionCreate()
  2. {
  3. if (!Yii::$app->user->isGuest) {
  4. $model = new Product();
  5.  
  6. if ($model->load(Yii::$app->request->post())) {
  7. $documentName=$model->id;
  8. $model->file=UploadedFile::getInstance($model,'file');
  9. $model->file->saveAs( 'uploads/'.$documentName.'.'.$model->file->extension);
  10. $model->document='uploads/'.$documentName.'.'.$model->file->extension;
  11. $model->save();
  12.  
  13. return $this->redirect(['index']);
  14. } else {
  15. return $this->render('create', [
  16. 'model' => $model,
  17. ]);
  18. }
  19. } else {
  20. $this->redirect('/site/index');
  21. }
  22. }
  23.  
  24. <p><a href="<?= $product->document?>" download>Скачать файл</a>
  25.  
  26. public function actionCreate()
  27. {
  28. if (!Yii::$app->user->isGuest) {
  29. $model = new Product();
  30.  
  31. if ($model->load(Yii::$app->request->post())) {
  32. $model->file=UploadedFile::getInstance($model,'file');
  33. $model->file->saveAs( 'uploads/'.$model->file->baseName.'.'.$model->file->extension);
  34. $model->document='uploads/'.$model->file->baseName.'.'.$model->file->extension;
  35. $model->save();
  36.  
  37. return $this->redirect(['index']);
  38. } else {
  39. return $this->render('create', [
  40. 'model' => $model,
  41. ]);
  42. }
  43. } else {
  44. $this->redirect('/site/index');
  45. }
  46. }
Add Comment
Please, Sign In to add comment