You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.4 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use yii\filters\VerbFilter;
  6. use yii\filters\AccessControl;
  7. use backend\models\LoginForm;
  8. use backend\models\CategorySearch;
  9. /**
  10. * Site controller
  11. */
  12. class SiteController extends Controller {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function behaviors() {
  17. return [
  18. 'access' => [
  19. 'class' => AccessControl::className(),
  20. 'rules' => [
  21. [
  22. 'actions' => ['login', 'error', 'test'],
  23. 'allow' => true,
  24. ],
  25. [
  26. 'actions' => ['logout', 'index'],
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. ],
  30. ],
  31. ],
  32. 'verbs' => [
  33. 'class' => VerbFilter::className(),
  34. 'actions' => [
  35. // 'logout' => ['post'],
  36. ],
  37. ],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function actions() {
  44. return [
  45. 'error' => [
  46. 'class' => 'yii\web\ErrorAction',
  47. ],
  48. 'upload'=>[
  49. 'class'=>'iron\actions\UploadAction',
  50. ]
  51. ];
  52. }
  53. /**
  54. * Displays homepage.
  55. *
  56. * @return string
  57. */
  58. public function actionIndex() {
  59. return $this->render('index');
  60. }
  61. /**
  62. * Login action.
  63. *
  64. * @return string
  65. */
  66. public function actionLogin() {
  67. $this->layout = 'base';
  68. if (!Yii::$app->user->isGuest) {
  69. return $this->goHome();
  70. }
  71. $model = new LoginForm();
  72. if ($model->load(Yii::$app->request->post()) && $model->login()) {
  73. return $this->goBack();
  74. } else {
  75. $model->password = '';
  76. return $this->render('login', [
  77. 'model' => $model,
  78. ]);
  79. }
  80. }
  81. /**
  82. * Logout action.
  83. *
  84. * @return string
  85. */
  86. public function actionLogout() {
  87. Yii::$app->user->logout();
  88. return $this->goHome();
  89. }
  90. public function actionTest() {
  91. $searchModel = new CategorySearch();
  92. return $this->render('test', [
  93. 'name' => 'blobt',
  94. 'model' => $searchModel
  95. ]);
  96. }
  97. }