| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace frontend\controllers;
- use Yii;
- use yii\web\NotFoundHttpException;
- class SiteController extends BaseController
- {
- /**
- * @inheritdoc
- */
- public function beforeAction($action)
- {
- return true;
- }
- /**
- * @return \yii\web\Response
- */
- public function actionIndex()
- {
- return $this->outJson(1, [], 'test ok!');
- }
- /**
- * 错误处理器
- * @return \yii\web\Response
- */
- public function actionError()
- {
- $errorHandler = Yii::$app->getErrorHandler();
- $exception = $errorHandler->exception;
- if ($exception == null) {
- $exception = new NotFoundHttpException();
- }
- Yii::$app->getResponse()->setStatusCodeByException($exception);
- return $this->outJson(0, [], Yii::$app->getResponse()->statusText);
- }
- }
|