From f5b2d9eaff1ca33f0812c8c645023af9517f9d52 Mon Sep 17 00:00:00 2001 From: "heqinhui_93@163.com" Date: Wed, 6 Jun 2018 20:40:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=BC=82=E5=B8=B8=E7=B1=BB?= =?UTF-8?q?=E5=B0=81=E8=A3=85=EF=BC=8C=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/config/main.php | 4 ---- api/controllers/BaseController.php | 16 ++++++++-------- api/controllers/ErrorController.php | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/api/config/main.php b/api/config/main.php index 4f68e30899..ad968b03eb 100644 --- a/api/config/main.php +++ b/api/config/main.php @@ -42,10 +42,6 @@ 'enableAutoLogin' => true, 'loginUrl' => null ], - 'session' => [ - // this is the name of the session cookie used for login on the backend - 'name' => 'advanced-api', - ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ diff --git a/api/controllers/BaseController.php b/api/controllers/BaseController.php index b193b366e5..ec10c35c83 100644 --- a/api/controllers/BaseController.php +++ b/api/controllers/BaseController.php @@ -14,7 +14,6 @@ use yii\helpers\ArrayHelper; use yii\rest\ActiveController; use yii\filters\auth\CompositeAuth; -use yii\filters\auth\QueryParamAuth; use yii\web\Response; use api\auth\Auth; @@ -79,15 +78,16 @@ public function behaviors() $this->enableCsrfValidation = false; }elseif(isset(Yii::$app->params['Authorization']) && !Yii::$app->params['Authorization']){ Yii::$app->user->login(User::findByUsername('root')); + }else{ + // 需要用户验证 + $behaviors['authenticator'] = [ + 'class' => CompositeAuth::className(), + 'authMethods' => [ + Auth::className(), + ], + ]; } - // 需要用户验证 - $behaviors['authenticator'] = [ - 'class' => CompositeAuth::className(), - 'authMethods' => [ - Auth::className(), - ], - ]; return $behaviors; } diff --git a/api/controllers/ErrorController.php b/api/controllers/ErrorController.php index 2533b9ed3e..6d46498ca3 100644 --- a/api/controllers/ErrorController.php +++ b/api/controllers/ErrorController.php @@ -7,11 +7,22 @@ */ namespace api\controllers; -class ErrorController extends BaseController +use yii\rest\Controller; +use yii\web\Response; + +class ErrorController extends Controller { - public $modelClass = ''; public function actionInfo() { + $response = \Yii::$app->response; + $statusCode = $response->statusCode; + $msg = Response::$httpStatuses[$statusCode]; + + $responseMsg['code'] = substr($statusCode, 0, 1) . '00' . substr($statusCode, 1, 2); + $responseMsg['message'] = $msg; + $responseMsg['data'] = ''; + + return $responseMsg; } } \ No newline at end of file