Yaf_Response_Abstract::clearBody

(Yaf >=1.0.0)

Yaf_Response_Abstract::clearBody丢弃所有已存在的响应 body

说明

public function Yaf_Response_Abstract::clearBody(string $key = ?): Yaf_Response_Abstract|false|null

丢弃所有已存在的响应 body。

参数

key

内容 key。若指定,则只清除该内容块;否则清除所有内容块。

返回值

成功时返回响应对象自身,失败时返回 null

示例

示例 #1 Yaf_Response_Abstract::clearBody() 示例

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $response = $this->getResponse();

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

        $response->clearBody("intro"); // 仅丢弃 "intro" 块
        var_dump($response->getBody(null));

        $response->clearBody(); // 丢弃所有 body 块
        var_dump($response->getBody(null));
    }
}
?>

以上示例的输出类似于:

array(1) {
  ["content"]=>
  string(5) "World"
}
array(0) {
}

参见