Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newShopBack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
newshop
newShopBack
Commits
81aacbf6
Commit
81aacbf6
authored
Dec 19, 2019
by
孙磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basecontroller
Signed-off-by:
sunlei
<
sunlei@romens.cn
>
parent
8d1196f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
BaseController.php
backend/controllers/v1/BaseController.php
+21
-17
No files found.
backend/controllers/v1/BaseController.php
View file @
81aacbf6
<?php
<?php
namespace
backend\controllers\v1
;
namespace
backend\controllers\v1
;
use
Yii
;
use
Yii
;
...
@@ -9,6 +10,7 @@ use yii\filters\auth\HttpBearerAuth;
...
@@ -9,6 +10,7 @@ use yii\filters\auth\HttpBearerAuth;
use
yii\filters\auth\QueryParamAuth
;
use
yii\filters\auth\QueryParamAuth
;
use
yii\filters\Cors
;
use
yii\filters\Cors
;
use
backend\components\v1\authorizationFilter
;
use
backend\components\v1\authorizationFilter
;
/**
/**
* Base controller
* Base controller
* 基类
* 基类
...
@@ -20,7 +22,7 @@ use backend\components\v1\authorizationFilter;
...
@@ -20,7 +22,7 @@ use backend\components\v1\authorizationFilter;
* ),
* ),
* @OA\Server(
* @OA\Server(
* description="Api server",
* description="Api server",
* url="/
zhangxiaolin/newshopback
",
* url="/
guoyongzhi/weiShopNew
",
* ),
* ),
* @OA\SecurityScheme(
* @OA\SecurityScheme(
* securityScheme="Authorization",
* securityScheme="Authorization",
...
@@ -64,30 +66,32 @@ class BaseController extends ActiveController
...
@@ -64,30 +66,32 @@ class BaseController extends ActiveController
$behaviors
=
parent
::
behaviors
();
$behaviors
=
parent
::
behaviors
();
// 跨域请求配置
// 跨域请求配置
$behaviors
=
array_merge
(
$behaviors
=
array_merge
(
[
[
'cors'
=>
[
'class'
=>
Cors
::
className
(),
'cors'
=>
[
'cors'
=>
[
'Origin'
=>
[
'http://localhost:8000'
,
'http://192.168.188.207:8000'
],
'class'
=>
Cors
::
className
(),
'Access-Control-Request-Method'
=>
[
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
,
'DELETE'
,
'HEAD'
,
'OPTIONS'
],
'cors'
=>
[
'Access-Control-Request-Headers'
=>
[
'*'
],
'Origin'
=>
[
'http://localhost:8000'
,
'http://192.168.188.207:8000'
],
'Access-Control-Allow-Credentials'
=>
true
,
'Access-Control-Request-Method'
=>
[
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
,
'DELETE'
,
'HEAD'
,
'OPTIONS'
],
'Access-Control-Max-Age'
=>
3600
,
'Access-Control-Request-Headers'
=>
[
'*'
],
'Access-Control-Expose-Headers'
=>
[
'*'
],
'Access-Control-Allow-Credentials'
=>
true
,
],
'Access-Control-Max-Age'
=>
3600
,
]
'Access-Control-Expose-Headers'
=>
[
'*'
],
],
$behaviors
);
],
]
],
$behaviors
);
// 格式化输出请求
// 格式化输出请求
$behaviors
[
'contentNegotiator'
][
'formats'
][
'text/html'
]
=
Response
::
FORMAT_JSON
;
$behaviors
[
'contentNegotiator'
][
'formats'
][
'text/html'
]
=
Response
::
FORMAT_JSON
;
//认证
//
认证
$behaviors
[
'HttpBearerAuth'
]
=
[
$behaviors
[
'HttpBearerAuth'
]
=
[
'class'
=>
HttpBearerAuth
::
className
(),
'class'
=>
HttpBearerAuth
::
className
(),
'optional'
=>
[
'login'
],
'optional'
=>
[
'login'
],
];
];
// 授权
// 授权
$behaviors
[
'authorizationFilter'
]
=
[
$behaviors
[
'authorizationFilter'
]
=
[
'class'
=>
authorizationFilter
::
className
(),
'class'
=>
authorizationFilter
::
className
(),
'optional'
=>
[
'login'
],
//过滤不需要验证的action
'optional'
=>
[
'login'
],
//过滤不需要验证的action
];
];
return
$behaviors
;
return
$behaviors
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment