SiteController.php 855 B

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