Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 访问Slim 3响应对象的数据_Php_Slim_Slim 3 - Fatal编程技术网

Php 访问Slim 3响应对象的数据

Php 访问Slim 3响应对象的数据,php,slim,slim-3,Php,Slim,Slim 3,我正在使用一个名为slim3的PHP框架,我想检查一下我的响应对象,我想知道为什么这是不可能的 官方文档声明响应对象实现PSR7响应接口,允许我检查身体 当我var\u dump($response->getBody();时,我只看到一个受保护的主体,我在任何地方都找不到我的$stack内容 文件说明了这一点,我想这就是原因。你能确认一下吗 提醒 响应对象是不可变的。此方法返回包含新正文的响应对象的副本 资料来源: PHP控制器类 class Controller { public fu

我正在使用一个名为slim3的PHP框架,我想检查一下我的
响应
对象,我想知道为什么这是不可能的

官方文档声明响应对象实现PSR7响应接口,允许我检查身体

当我
var\u dump($response->getBody();
时,我只看到一个
受保护的
主体,我在任何地方都找不到我的
$stack
内容

文件说明了这一点,我想这就是原因。你能确认一下吗

提醒 响应对象是不可变的。此方法返回包含新正文的响应对象的副本

资料来源:

PHP控制器类

class Controller
{
    public function index($request, $response, $args)
    {
        // code

        $stack    = array($cars, $manufacturers);
        $response = $response->withJson($stack);

        return $response->withStatus(200);
    }
}
变量转储的输出

class Slim\Http\Response#201 (5) {
  protected $status =>
  int(200)
  protected $reasonPhrase =>
  string(2) "OK"
  protected $protocolVersion =>
  string(3) "1.1"
  protected $headers =>
  class Slim\Http\Headers#200 (1) {
    protected $data =>
    array(1) {
      'content-type' =>
      array(2) {
        ...
      }
    }
  }
  protected $body =>
  class Slim\Http\Body#202 (7) {
    protected $stream =>
    resource(87) of type (stream)
    protected $meta =>
    array(6) {
      'wrapper_type' =>
      string(3) "PHP"
      'stream_type' =>
      string(4) "TEMP"
      'mode' =>
      string(3) "w+b"
      'unread_bytes' =>
      int(0)
      'seekable' =>
      bool(true)
      'uri' =>
      string(10) "php://temp"
    }
    protected $readable =>
    NULL
    protected $writable =>
    bool(true)
    protected $seekable =>
    NULL
    protected $size =>
    NULL
    protected $isPipe =>
    NULL
  }
}

内容将写入HTTP响应体流

$content=$response->getBody()->;

$content=(string)$response->getBody();

我可以问一下,这是您通常拥有的特殊PHP知识,还是您必须查找才能为我提供答案?我发现这令人惊讶。的文档中包含了这些信息。我还必须搜索并尝试一些东西,直到找到答案。