首页 > 解决方案 > 解决此错误的可能方法是什么?我正在将我的项目从 cakephp 2.x 迁移到 cakephp 4.x

问题描述

我正在将我的项目从 cakephp 2.x 迁移到 cakephp 4.x ......在我的编辑功能中,我收到了这个错误:

用于(string)$request->getBody()获取原始 PHP 输入作为字符串;用于BodyParserMiddleware解析请求正文,以便通过 $request->getParsedBody() - /home/customer/www/cakephp4.sfamcdc.ednc.solutions/public_html/src/Controller/Api/UsersController.php 作为数组/对象使用, line: 256 您可以通过设置Error.errorLevel来禁用所有弃用警告E_ALL & ~E_USER_DEPRECATED,或者在您的中添加src/Controller/Api/UsersController.php以 仅从此文件中静音弃用。[CORE/src/Core/functions.php,第 316 行]Error.ignoredDeprecationPathsconfig/app.php

在我的 UsersController 中,我试图查看在我的 service.js 中传递给我的 API 的数据,这是我的代码:

$jsonData = $this->request->input('json_decode');

调试($jsonData);

这是我的 service.js 上的更新代码:

更新: {

  method: 'PUT',

  headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' },

  transformRequest: function(data) {
    
    $data = data;

    var formData = new FormData();

    formData.append('data', JSON.stringify($data));
    
    fileImage = document.getElementById('fileImage');

    if (fileImage != null && fileImage.files.length > 0)

      formData.append('file', fileImage.files[0]);      
    
    return formData;

  }



}

标签: cakephp

解决方案


推荐阅读