【问题标题】:PHP Slim Framework v3 - Set global content-type for responsesPHP Slim Framework v3 - 为响应设置全局内容类型
【发布时间】:2016-09-12 08:15:46
【问题描述】:

有没有办法在 SLIM 3 中将内容类型设置为“application/json”以进行全局响应?

我尝试了以下不起作用的方法:

$app->contentType('application/json');
$app->response->headers->set('Content-Type', 'application/json');

【问题讨论】:

    标签: php json rest content-type slim


    【解决方案1】:

    Middleware:

    $app->add(function ($request, $response, $next) {
        return $response->withHeader('Content-Type', 'application/json');
    });
    

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 1970-01-01
      • 2015-10-09
      • 2018-05-12
      • 2021-04-20
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      相关资源
      最近更新 更多