I18nSourceMessageController.php 3.2 KB

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