axios post YII2无法接收post参数问题解决

axios post YII2无法接收post参数问题解决

在yii 配置文件中增加 ‘parsers’ => [“application/json” => “yii\web\JsonParser”] 如下所示:

$config = [
    'id' => 'basic',
    'language' => 'zh-CN',
    'timeZone' => env('TIME_ZONE', 'PRC'),
    'basePath' => $basePath,
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm' => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            'class' => 'app\hejiang\Request',
            'cookieValidationKey' => env('COOKIE_KEY', '123'),
            'parsers' => ["application/json" => "yii\web\JsonParser"],
        ],
        
    ]
    ...
  ]   

如果配置文件不是默认的local-main.php,如何查看配置文件是哪个?

打开 项目服务web目录的index.php,查找启动语句

我的如下:

$app = new app\myProject\Application();
$app->run();

再找到根目录\myProject目录下的Application.php

public function __construct($configFile = '/config/web.php')
    {
        $this->loadDotEnv()
            ->defineConstants();

        $basePath = dirname(__DIR__);
        require $basePath . '/vendor/yiisoft/yii2/Yii.php';

        $this->loadYiiHelpers();
        parent::__construct(require $basePath . $configFile);

        $this->enableJsonResponse()
            ->enableErrorReporting();
    }

看构造函数
这里的 $configFile就是了,我的被改成了web.php

你可能感兴趣的:(axios)