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

Yaf_Response_Abstract::setBody

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Set content to the response

Description

Yaf_Response_Abstract::setBody(string $body, [string $key]): Yaf_Response_Abstract|false|null

Set content to the response

Parameters

body

The content string.

key

the content key. If not specified, Yaf_Response_Abstract::DEFAULT_BODY will be used.

Return Values

Returns the response object itself on success, or false on failure.

Examples

Yaf_Response_Abstract::setBody() example

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

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

print_r($response);
echo $response;
?>

The above example will output something similar to:

output
Yaf_Response_Http Object
(
    [_header:protected] => Array
        (
        )

    [_body:protected] => Array
        (
            [content] => Hello
            [footer] =>  World
        )

    [_sendheader:protected] => 1
    [_response_code:protected] => 200
)
Hello World

See Also

  • Yaf_Response_Abstract::getBody
  • Yaf_Response_Abstract::appendBody
  • Yaf_Response_Abstract::prependBody
  • Yaf_Response_Abstract::clearBody

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