ReportTopicController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace manager\controllers;
  3. use app\models\ReportTopic;
  4. use yii\data\ActiveDataProvider;
  5. use yii\web\Controller;
  6. use yii\web\NotFoundHttpException;
  7. use yii\filters\VerbFilter;
  8. /**
  9. * ReportTopicController implements the CRUD actions for ReportTopic model.
  10. */
  11. class ReportTopicController extends BaseController
  12. {
  13. /**
  14. * @inheritDoc
  15. */
  16. public function behaviors()
  17. {
  18. return array_merge(
  19. parent::behaviors(),
  20. [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. 'delete' => ['POST'],
  25. ],
  26. ],
  27. ]
  28. );
  29. }
  30. /**
  31. * Lists all ReportTopic models.
  32. *
  33. * @return string
  34. */
  35. public function actionIndex()
  36. {
  37. $dataProvider = new ActiveDataProvider([
  38. 'query' => ReportTopic::find()->where(['<>', 'title', '']),
  39. 'pagination' => [
  40. 'pageSize' => 50
  41. ],
  42. 'sort' => [
  43. 'defaultOrder' => [
  44. 'id' => SORT_DESC,
  45. ]
  46. ],
  47. ]);
  48. return $this->render('index', [
  49. 'dataProvider' => $dataProvider,
  50. ]);
  51. }
  52. /**
  53. * Displays a single ReportTopic model.
  54. * @param int $id ID
  55. * @return string
  56. * @throws NotFoundHttpException if the model cannot be found
  57. */
  58. public function actionView($id)
  59. {
  60. return $this->render('view', [
  61. 'model' => $this->findModel($id),
  62. ]);
  63. }
  64. /**
  65. * Creates a new ReportTopic model.
  66. * If creation is successful, the browser will be redirected to the 'view' page.
  67. * @return string|\yii\web\Response
  68. */
  69. public function actionCreate()
  70. {
  71. $model = new ReportTopic();
  72. if ($this->request->isPost) {
  73. if ($model->load($this->request->post()) && $model->save()) {
  74. return $this->redirect(['view', 'id' => $model->id]);
  75. }
  76. } else {
  77. $model->loadDefaultValues();
  78. }
  79. return $this->render('create', [
  80. 'model' => $model,
  81. ]);
  82. }
  83. /**
  84. * Updates an existing ReportTopic model.
  85. * If update is successful, the browser will be redirected to the 'view' page.
  86. * @param int $id ID
  87. * @return string|\yii\web\Response
  88. * @throws NotFoundHttpException if the model cannot be found
  89. */
  90. public function actionUpdate($id)
  91. {
  92. $model = $this->findModel($id);
  93. if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
  94. return $this->redirect(['view', 'id' => $model->id]);
  95. }
  96. return $this->render('update', [
  97. 'model' => $model,
  98. ]);
  99. }
  100. /**
  101. * Deletes an existing ReportTopic model.
  102. * If deletion is successful, the browser will be redirected to the 'index' page.
  103. * @param int $id ID
  104. * @return \yii\web\Response
  105. * @throws NotFoundHttpException if the model cannot be found
  106. */
  107. public function actionDelete($id)
  108. {
  109. $this->findModel($id)->delete();
  110. return $this->redirect(['index']);
  111. }
  112. /**
  113. * Finds the ReportTopic model based on its primary key value.
  114. * If the model is not found, a 404 HTTP exception will be thrown.
  115. * @param int $id ID
  116. * @return ReportTopic the loaded model
  117. * @throws NotFoundHttpException if the model cannot be found
  118. */
  119. protected function findModel($id)
  120. {
  121. if (($model = ReportTopic::findOne(['id' => $id])) !== null) {
  122. return $model;
  123. }
  124. throw new NotFoundHttpException('The requested page does not exist.');
  125. }
  126. }