SiteController.php 881 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\web\NotFoundHttpException;
  5. /**
  6. * Site controller
  7. */
  8. class SiteController extends BaseController
  9. {
  10. /**
  11. * @inheritdoc
  12. */
  13. public function beforeAction($action)
  14. {
  15. return true;
  16. }
  17. /**
  18. * @return \yii\web\Response
  19. */
  20. public function actionIndex()
  21. {
  22. return $this->outJson(1, [], 'test ok!');
  23. }
  24. /**
  25. * 错误处理器
  26. * @return \yii\web\Response
  27. */
  28. public function actionError()
  29. {
  30. $errorHandler = Yii::$app->getErrorHandler();
  31. $exception = $errorHandler->exception;
  32. if ($exception == null) {
  33. $exception = new NotFoundHttpException();
  34. }
  35. Yii::$app->getResponse()->setStatusCodeByException($exception);
  36. return $this->outJson(0, [], Yii::$app->getResponse()->statusText);
  37. }
  38. }