在访问API时必须为cookieValidationKey配置一

在访问API时必须为cookieValidationKey配置一

本文介绍了Yii2无效配置,在访问API时必须为cookieValidationKey配置一个秘密密钥错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

每当尝试访问自己编写的API时都会遇到错误。

I am encountering an error whenever I am trying to access my self written API.

我已经详细研究了这个问题,尝试过解决方案在我的 config / main.php

I have looked at this problem in detail and tried this solution in my config/main.php

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php'),
    require(__DIR__ .'/main-local.php')
);
'components' => [
        'request' => [

            'enableCookieValidation' => false,
            'enableCsrfValidation' => false,

        ],


'request' => [

'enableCookieValidation' => false,// also set it to true

'enableCsrfValidation' => false, // also set it to true
],

/config/main-local.php 我关注了

'components' => [
    'request' => [
        // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
        'cookieValidationKey' => 'someRandomKey',

    ],
],

不为我工作。任何帮助将不胜感激。

It's not working for me. Any help would be highly appreciated.

推荐答案

从中删除 request 组件 common / config / main-local.php 并将其保存在 frontend / config / main-local.php 。

Remove the request component from the common/config/main-local.php and just keep it into the frontend/config/main-local.php.

然后在下的 api / config / main.php 中添加以下内容

 'components' => [
        'request' => [
            'enableCookieValidation' => false,
            'enableCsrfValidation' => false,
        ],

这篇关于Yii2无效配置,在访问API时必须为cookieValidationKey配置一个秘密密钥错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:12