DocumentsToTheUserController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use app\models\DocumentsToTheUser;
  5. use app\models\DocumentsToTheUserSearch;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use yii\web\UploadedFile;
  10. /**
  11. * DocumentsToTheUserController implements the CRUD actions for DocumentsToTheUser model.
  12. */
  13. class DocumentsToTheUserController extends Controller
  14. {
  15. public $layout = '@app/views/layouts/backend/user';
  16. /**
  17. * @inheritdoc
  18. */
  19. public function behaviors()
  20. {
  21. return [
  22. 'verbs' => [
  23. 'class' => VerbFilter::className(),
  24. 'actions' => [
  25. 'delete' => ['POST'],
  26. ],
  27. ],
  28. ];
  29. }
  30. /**
  31. * Lists all DocumentsToTheUser models.
  32. * @return mixed
  33. */
  34. public function actionIndex()
  35. {
  36. $searchModel = new DocumentsToTheUserSearch();
  37. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  38. return $this->render('index', [
  39. 'searchModel' => $searchModel,
  40. 'dataProvider' => $dataProvider,
  41. ]);
  42. }
  43. /**
  44. * Displays a single DocumentsToTheUser model.
  45. * @param integer $id
  46. * @return mixed
  47. */
  48. public function actionView($id)
  49. {
  50. return $this->render('view', [
  51. 'model' => $this->findModel($id),
  52. ]);
  53. }
  54. /**
  55. * Creates a new DocumentsToTheUser model.
  56. * If creation is successful, the browser will be *.doc *.docx *.pdf *.png *.jpg *.tiff, *.zip *rarredirected to the 'view' page.
  57. * @return mixed
  58. */
  59. public function actionCreate()
  60. {
  61. $model = new DocumentsToTheUser();
  62. if ($model->load(Yii::$app->request->post()) && $model->upload()) {
  63. // file is uploaded successfully
  64. return $this->redirect(['view', 'id' => $model->id]);
  65. }
  66. return $this->render('create', [
  67. 'model' => $model,
  68. ]);
  69. }
  70. /**
  71. * Updates an existing DocumentsToTheUser model.
  72. * If update is successful, the browser will be redirected to the 'view' page.
  73. * @param integer $id
  74. * @return mixed
  75. */
  76. public function actionUpdate($id)
  77. {
  78. $model = $this->findModel($id);
  79. if ($model->load(Yii::$app->request->post()) && $model->upload()) {
  80. return $this->redirect(['view', 'id' => $model->id]);
  81. } else {
  82. return $this->render('update', [
  83. 'model' => $model,
  84. ]);
  85. }
  86. }
  87. /**
  88. * Deletes an existing DocumentsToTheUser model.
  89. * If deletion is successful, the browser will be redirected to the 'index' page.
  90. * @param integer $id
  91. * @return mixed
  92. */
  93. public function actionDelete($id)
  94. {
  95. $this->findModel($id)->delete();
  96. return $this->redirect(['index']);
  97. }
  98. /**
  99. * Finds the DocumentsToTheUser model based on its primary key value.
  100. * If the model is not found, a 404 HTTP exception will be thrown.
  101. * @param integer $id
  102. * @return DocumentsToTheUser the loaded model
  103. * @throws NotFoundHttpException if the model cannot be found
  104. */
  105. protected function findModel($id)
  106. {
  107. if (($model = DocumentsToTheUser::findOne($id)) !== null) {
  108. return $model;
  109. } else {
  110. throw new NotFoundHttpException('The requested page does not exist.');
  111. }
  112. }
  113. }