php8.5
Home/ Manual/ yaf / yaf_response_abstract/ Yaf_Response_Abstract::getBody

Yaf_Response_Abstract::getBody

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve a response body block

Description

Yaf_Response_Abstract::getBody([string $key]): mixed

Retrieve the content of a response body block.

Parameters

key

The content key. If not specified, the DEFAULT_BODY block is used; pass null to get all content blocks as an array.

Return Values

The content string, or an array of all content blocks when key is null. Returns an empty string if the block is not set.

Examples

Yaf_Response_Abstract::getBody() example

php
<?php
$response = new Yaf_Response_Http();

$response->setBody("Hello")->setBody(" World", "footer");

var_dump($response->getBody());
var_dump($response->getBody(Yaf_Response_Abstract::DEFAULT_BODY));
var_dump($response->getBody("footer"));
var_dump($response->getBody(NULL));
?>

The above example will output something similar to:

output
string(5) "Hello"
string(5) "Hello"
string(6) " World"
array(2) {
  ["content"]=>
  string(5) "Hello"
  ["footer"]=>
  string(6) " World"
}

See Also

  • Yaf_Response_Abstract::setBody
  • Yaf_Response_Abstract::appendBody
  • Yaf_Response_Abstract::prependBody
  • Yaf_Response_Abstract::clearBody

Source: reference/yaf/yaf_response_abstract/getbody.xml · from the official PHP manual (php/doc-en)