SettingsController.php 3.3 KB

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