Commit 81aacbf6 authored by 孙磊's avatar 孙磊

basecontroller

Signed-off-by: 孙磊's avatarsunlei <sunlei@romens.cn>
parent 8d1196f2
<?php
namespace backend\controllers\v1;
use Yii;
......@@ -9,6 +10,7 @@ use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use yii\filters\Cors;
use backend\components\v1\authorizationFilter;
/**
* Base controller
* 基类
......@@ -20,7 +22,7 @@ use backend\components\v1\authorizationFilter;
* ),
* @OA\Server(
* description="Api server",
* url="/zhangxiaolin/newshopback",
* url="/guoyongzhi/weiShopNew",
* ),
* @OA\SecurityScheme(
* securityScheme="Authorization",
......@@ -64,30 +66,32 @@ class BaseController extends ActiveController
$behaviors = parent::behaviors();
// 跨域请求配置
$behaviors = array_merge(
[
'cors'=>[
'class' => Cors::className(),
[
'cors' => [
'Origin' => ['http://localhost:8000','http://192.168.188.207:8000'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600,
'Access-Control-Expose-Headers' => ['*'],
],
]
],$behaviors);
'class' => Cors::className(),
'cors' => [
'Origin' => ['http://localhost:8000', 'http://192.168.188.207:8000'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600,
'Access-Control-Expose-Headers' => ['*'],
],
]
],
$behaviors
);
// 格式化输出请求
$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
//认证
$behaviors['HttpBearerAuth']=[
// 认证
$behaviors['HttpBearerAuth'] = [
'class' => HttpBearerAuth::className(),
'optional' => ['login'],
];
// 授权
$behaviors['authorizationFilter']=[
$behaviors['authorizationFilter'] = [
'class' => authorizationFilter::className(),
'optional' => ['login'],//过滤不需要验证的action
'optional' => ['login'], //过滤不需要验证的action
];
return $behaviors;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment