gpt4 book ai didi

php - 在 Window XAMPP 中的本地系统中设置 Yii2 项目出现错误

转载 作者:可可西里 更新时间:2023-11-01 10:10:45 24 4
gpt4 key购买 nike

我正在 XAMPP 窗口中的本地系统中设置 Yii2 项目,但出现错误:

Declaration of common\components\Request::validateCsrfToken() should be compatible with yii\web\Request::validateCsrfToken($clientSuppliedToken = NULL)

here is error screen capture

但是代码在 Ubuntu 服务器上运行良好。

这是我的validateCsrfToken() 方法:

public function validateCsrfToken()
{
if($this->enableCsrfValidation && in_array(Yii::$app->getUrlManager()->parseRequest($this)[0], $this->noCsrfRoutes)){
return true;
}
return parent::validateCsrfToken();
}

最佳答案

这个问题是因为您在 Windows 中使用 strict PHP,但在 Linux 中没有。您拥有的函数 common\components\Request::validateCsrfToken() 应该与 yii\web\Request::validateCsrfToken() 兼容。这意味着,它需要具有相同的签名。

你现在能做的就是把自己的函数改成

public function validateCsrfToken($token = NULL) { 
if ($this->enableCsrfValidation && in_array(Yii::$app->getUrlManager()->parseRequest($this)[0], $this->noCsrfRoutes)) {
return true;
}

return parent::validateCsrfToken($token);
}

每次重写其中一个函数(即 beforeActionafterActionbeforeSave 等等)时都需要这样做。 .)

关于php - 在 Window XAMPP 中的本地系统中设置 Yii2 项目出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57375474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com