初始化仓库
This commit is contained in:
37
common/core/BasePlatformController.php
Normal file
37
common/core/BasePlatformController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace common\core;
|
||||
|
||||
use common\foundation\Cors;
|
||||
use common\models\Config;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
|
||||
class BasePlatformController extends BaseController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
// 多语言,需要在http header中设置 app-language:zh-CN
|
||||
//Yii::$app->language = Yii::$app->request->getHeaders()->get('app-language'); //'en-US';
|
||||
\Yii::$app->params['web'] = Config::lists();
|
||||
}
|
||||
|
||||
final public function behaviors()
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
$newBehaviors = [];
|
||||
$newBehaviors['corsFilter'] = [
|
||||
'class' => Cors::class,
|
||||
];
|
||||
foreach ($behaviors as $k=>$v){
|
||||
$newBehaviors[$k]=$v;
|
||||
}
|
||||
unset($behaviors['authenticator']); //删掉,保持先cors,后authenticator
|
||||
//设置认证方式,接口才认证
|
||||
$newBehaviors['authenticator'] = [
|
||||
'class' => HttpBearerAuth::class,
|
||||
'optional' => $this->optional,
|
||||
];
|
||||
return $newBehaviors;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user