CustomController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Author: NODELOG
  4. * Date: 2016/1/11
  5. * Time: 17:59.
  6. */
  7. namespace common\modules\config\backend\controllers;
  8. use common\modules\config\models\Config;
  9. use Yii;
  10. use yii\data\ActiveDataProvider;
  11. use yii\helpers\Url;
  12. use yii\web\Controller;
  13. use yii\web\NotFoundHttpException;
  14. class CustomController extends Controller
  15. {
  16. /**
  17. * Lists all Config models.
  18. *
  19. * @return mixed
  20. */
  21. public function actionIndex()
  22. {
  23. Url::remember();
  24. $query = Config::find();
  25. $dataProvider = new ActiveDataProvider([
  26. 'query' => $query,
  27. ]);
  28. return $this->render('index', [
  29. 'dataProvider' => $dataProvider,
  30. ]);
  31. }
  32. /**
  33. * Displays a single Config model.
  34. *
  35. * @param int $id
  36. *
  37. * @return mixed
  38. */
  39. public function actionView($id)
  40. {
  41. return $this->render('view', [
  42. 'model' => $this->findModel($id),
  43. ]);
  44. }
  45. /**
  46. * Creates a new Config model.
  47. * If creation is successful, the browser will be redirected to the 'view' page.
  48. *
  49. * @return mixed
  50. */
  51. public function actionCreate()
  52. {
  53. $model = new Config();
  54. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  55. Yii::$app->session->setFlash('success', '添加成功');
  56. return $this->goBack();
  57. } else {
  58. return $this->render('create', [
  59. 'model' => $model,
  60. ]);
  61. }
  62. }
  63. /**
  64. * Updates an existing Config model.
  65. * If update is successful, the browser will be redirected to the 'view' page.
  66. *
  67. * @param int $id
  68. *
  69. * @return mixed
  70. */
  71. public function actionUpdate($id)
  72. {
  73. $model = $this->findModel($id);
  74. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  75. Yii::$app->session->setFlash('success', '更新成功');
  76. return $this->goBack();
  77. } else {
  78. return $this->render('update', [
  79. 'model' => $model,
  80. ]);
  81. }
  82. }
  83. /**
  84. * Deletes an existing Config model.
  85. * If deletion is successful, the browser will be redirected to the 'index' page.
  86. *
  87. * @param int $id
  88. *
  89. * @return mixed
  90. */
  91. public function actionDelete($id)
  92. {
  93. $this->findModel($id)->delete();
  94. Yii::$app->session->setFlash('success', '删除成功');
  95. return $this->goBack();
  96. }
  97. /**
  98. * Finds the Config model based on its primary key value.
  99. * If the model is not found, a 404 HTTP exception will be thrown.
  100. *
  101. * @param int $id
  102. *
  103. * @return Config the loaded model
  104. *
  105. * @throws NotFoundHttpException if the model cannot be found
  106. */
  107. protected function findModel($id)
  108. {
  109. if (($model = Config::findOne($id)) !== null) {
  110. return $model;
  111. } else {
  112. throw new NotFoundHttpException('The requested page does not exist.');
  113. }
  114. }
  115. }