## 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