【问题标题】:Codeigniter 4 ResourceController - minify json outputCodeigniter 4 ResourceController - 缩小 json 输出
【发布时间】:2021-12-27 14:14:49
【问题描述】:

我正在使用 Codeigniter 的资源控制器从我的 API 中输出一些日期。

例如:

$data = ['id' => 8, 'name': 'John Doe', 'age': 27];
return $this->respond($data, 200);

有没有办法缩小输出?

【问题讨论】:

  • 这能回答你的问题吗? How to minify json response?
  • 有点像,有点像不像。如果我这样做,响应是一个字符串,codeignter 将标题设置为 text/html。我认为它会起作用。我希望有一个 codeigniter 设置或一些配置值。

标签: php json codeigniter-4


【解决方案1】:

你可能想这样做:

$data = ['id' => 8, 'name': 'John Doe', 'age': 27];

   //add the header here
    header('Content-Type: application/json');
    echo json_encode( $data );

使用标题类型来正确处理

我希望有一个 codeigniter 设置或一些配置值。

没有这样的东西,内置的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 2020-07-18
    相关资源
    最近更新 更多