## Yaf_Request_Http
代表了一個實際的Http請求, 一般的不用自己實例化它, Yaf_Application在run以后會自動根據當前請求實例它,在控制器內可以使用$this->getRequest()來獲取請求信息。
更多Yaf_Request_Http類的內容可參見文檔: http://www.laruence.com/manual/yaf.class.request.html#yaf.class.request.http
#### 使用示例
`<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction($name='', $value='') {
print_r($this->getRequest()->getQuery());
}`
擴展Yaf_Request_Http,比如加上過濾,數據處理等。先在library定義一個request的類,再在Bootstrap.php里設置Request
### 文件示例:library/Request.php
`<?php
class Request extends Yaf_Request_Http
{
private $_posts;
private $_params;
private $_query;
public function getPost()
{
if ($this->_posts) {
return $this->_posts;
}
$this->_posts = $this->filter_params(parent::getPost());
return $this->_posts;
}
public function getParams()
{
if ($this->_params) {
return $this->_params;
}
$this->_params = $this->filter_params(parent::getParams());
return $this->_params;
}
public function getQuery()
{
if ($this->_query) {
return $this->_query;
}
$this->_query = $this->filter_params(parent::getQuery());
return $this->_query;
}
private function filter_params($params)
{
if (!empty($params)) {
array_walk_recursive($params, function(&$value, $key){
$value=htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
});
}
return $params;
}
}`
### 文件示例:Bootstrap.php
`<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initRequest(Yaf_Dispatcher $dispatcher)
{
$dispatcher->setRequest(new Request());
}`
#### 然后在控制器中可以使用$this->getRequest()->getQuery()來獲取參數
`<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
print_r($this->getRequest()->getQuery());
}`
#### 關于更多的該類的使用方法,可以參考:
http://www.laruence.com/manual/yaf.class.request.html