CompereController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\Region;
  4. use Yii;
  5. use common\models\Compere;
  6. use backend\models\search\CompereSearch;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. /**
  11. * CompereController implements the CRUD actions for Compere model.
  12. */
  13. class CompereController 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. ];
  28. }
  29. public function actions()
  30. {
  31. $actions=parent::actions();
  32. $actions['get-region']=[
  33. 'class'=>\chenkby\region\RegionAction::className(),
  34. 'model'=>Region::className()
  35. ];
  36. return $actions;
  37. }
  38. /**
  39. * Lists all Compere models.
  40. * @return mixed
  41. */
  42. public function actionIndex()
  43. {
  44. $searchModel = new CompereSearch();
  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 Compere 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 Compere 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 Compere();
  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 Compere 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 Compere 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)->softDelete();
  104. Yii::$app->session->setFlash('success', '操作成功');
  105. return $this->redirect(['index']);
  106. }
  107. /**
  108. * Finds the Compere model based on its primary key value.
  109. * If the model is not found, a 404 HTTP exception will be thrown.
  110. * @param integer $id
  111. * @return Compere the loaded model
  112. * @throws NotFoundHttpException if the model cannot be found
  113. */
  114. protected function findModel($id)
  115. {
  116. if (($model = Compere::findOne($id)) !== null) {
  117. return $model;
  118. } else {
  119. throw new NotFoundHttpException('The requested page does not exist.');
  120. }
  121. }
  122. }