问题:NO 'Access-Control_Allow-Origin' header is present on the requested resource.
解决方案
<?php
namespace appmodulesv1controllers;
use Yii;
use yiiwebResponse;
class BaseAPIController extends yii
estController
{
public $serializer = [
'class' => 'yii
estSerializer',
'collectionEnvelope' => 'items',
];
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['contentNegotiator']['formats'] = [
'application/json' => Response::FORMAT_JSON
];
$behaviors['access'] = [
'class' => 'yiifiltersAccessControl',
'rules' => [
[
'allow' => true,
'matchCallback' => function ($rule, $action) {
return in_array(Yii::$app->request->hostInfo, Yii::$app->params['acceptableHosts']);
}
]
]
];
$behaviors['corsFilter'] = [
'class' => 'yiifiltersCors',
'cors' => [
'Origin' => Yii::$app->params['acceptableHosts'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 86400,
'Access-Control-Expose-Headers' => [],
],
];
return $behaviors;
}
}