38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
||
|
||
namespace common\core;
|
||
|
||
use common\foundation\Cors;
|
||
use common\models\oldDb\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;
|
||
}
|
||
}
|