php 如何获取Symfony2中的所有帖子参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10738647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get all post parameters in Symfony2?
提问by Akrramo
I want to get all post parameters of a symfonyForm.
我想获取symfony表单的所有 post 参数。
I used :
我用了 :
$all_parameter = $this->get('request')->getParameterHolder()->getAll();
and I get this error
我收到这个错误
Fatal error: Call to undefined method Symfony\Component\HttpFoundation\Request::getParameterHolder() in /Library/WebServer/Documents/Symfony/src/Uae/PortailBundle/Controller/NoteController.php on line 95
回答by Mun Mun Das
$this->get('request')->request->all()
回答by Peter Bailey
Symfony Request Objectshave quite a few public properties that represent different parts of the request. Probably the easiest way to describe it is to show you the code for Request::initialize()
Symfony请求对象有相当多的公共属性代表请求的不同部分。描述它的最简单方法可能是向您展示代码Request::initialize()
/**
* Sets the parameters for this request.
*
* This method also re-initializes all properties.
*
* @param array $query The GET parameters
* @param array $request The POST parameters
* @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
* @param array $cookies The COOKIE parameters
* @param array $files The FILES parameters
* @param array $server The SERVER parameters
* @param string $content The raw body data
*
* @api
*/
public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
{
$this->request = new ParameterBag($request);
$this->query = new ParameterBag($query);
$this->attributes = new ParameterBag($attributes);
$this->cookies = new ParameterBag($cookies);
$this->files = new FileBag($files);
$this->server = new ServerBag($server);
$this->headers = new HeaderBag($this->server->getHeaders());
$this->content = $content;
$this->languages = null;
$this->charsets = null;
$this->acceptableContentTypes = null;
$this->pathInfo = null;
$this->requestUri = null;
$this->baseUrl = null;
$this->basePath = null;
$this->method = null;
$this->format = null;
}
So, as you can see, Request::$requestis a ParameterBagof the POST parameters.
因此,如您所见,Request::$request是ParameterBagPOST 参数的一个。

