Skip to content

Commit

Permalink
完善异常类封装,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jun 6, 2018
1 parent de479c8 commit f5b2d9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 0 additions & 4 deletions api/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
16 changes: 8 additions & 8 deletions api/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
15 changes: 13 additions & 2 deletions api/controllers/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit f5b2d9e

Please sign in to comment.