# 響應-Response
## Yaf官方的響應處理
**1、設置響應信息**
* setHeader:設置響應頭信息
* setAllHeaders:批量設置響應頭
* setBody:設置響應體信息
* appendBody:在現在的body后面添加新的響應體
* prependBody:在現在的body前面添加新的響應體
* clearHeaders:清除頭部的設置
* clearBody:清除響應體的設置
在不設置響應頭信息的時候:
~~~
<?php
class TestController extends \Yaf_Controller_Abstract
{
public function init()
{
}
public function testAction()
{
echo 'test';
}
}
~~~
直接輸出:test
然后設置響應頭:
~~~
$res = $this->getResponse();
$res -> setHeader( 'Content-Type', 'text/html; charset=utf-8' );
$headers =array('Content-Type'=>'text/html;charset=utf-8', 'Server'=>'Yaf Server');
$res->setAllHeaders($headers);
$res->appendBody('after content<br>');
$res->setBody('main content<br>');
$res->prependBody('before content<br>');
var_dump($res->getHeader());
~~~
**2、獲取響應信息:獲取設置的響應信息**
~~~
getHeader:獲取某個響應頭信息
getBody:獲取響應體信息
~~~
## Yaf的響應類可以參考:
[http://www.laruence.com/manual/yaf.class.response.html](http://www.laruence.com/manual/yaf.class.response.html)
[http://php.net/manual/zh/class.yaf-response-abstract.php](http://php.net/manual/zh/class.yaf-response-abstract.php)
- 序言
- 安裝 Yaf
- Yaf基礎知識
- 1.運行流程
- 2.YAF架構
- 3.目錄結構
- 4.Yaf的配置
- 5.Yaf的Bootstrap
- 6.Yaf的多模塊配置
- 7.Yaf中使用命名空間
- 本書框架配置
- 1.框架目錄結構
- 2.數據庫配置
- 3.緩存配置
- 4.全局配置
- 5.公共助手函數
- 請求與響應
- 1.請求-Request
- 2.響應-Response
- 數據庫操作
- 使用think-orm
- 接口開發
- 1.RESTful接口設計
- 2.Yar RPC接口設計
- 數據驗證
- 數據驗證 - validate
- 網頁開發
- Session
- Cookie
- 路由設置
- 工具類
- 1.Rsa加密
- 2.Random快速生成隨機數
- 3.Cache - 緩存
- 4.Weapp - 微信小程序類
- 5.Qiniu - 七牛云存儲使用
- 6.支付類(微信&支付寶)
- 7.Logs - 日志記錄