HelpVideoController.php 3.4 KB

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