Files
xk-api-yii/common/core/BaseAppController.php

46 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace common\core;
use common\foundation\Cors;
use common\models\oldDb\Config;
use member\behaviors\MallBehavior;
use yii\filters\auth\HttpBearerAuth;
class BaseAppController 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,
];
$newBehaviors['storeId'] = [
'class' => MallBehavior::class,
];
return $newBehaviors;
}
}