如何获取Symfony2中的所有帖子参数?

Moh*_*med 28 php symfony

我想获得symfony Form的所有post参数.

我用了 :

$all_parameter = $this->get('request')->getParameterHolder()->getAll();
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

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
Run Code Online (Sandbox Code Playgroud)

Mun*_*Das 83

$this->get('request')->request->all()
Run Code Online (Sandbox Code Playgroud)

  • 当`Request $ request`是控制器动作的参数时:`$ request-> request-> all()` (19认同)
  • 我认为`$ this-> get('request')`在2.8中被弃用,并在3.0中删除.没有确认.无论如何,@ jmq评论将其钉住了. (3认同)

Pet*_*ley 9

Symfony Request Objects有很多公共属性,代表请求的不同部分.描述它的最简单方法可能是向您展示代码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;
}
Run Code Online (Sandbox Code Playgroud)

因此,正如您所看到的,Request::$request是一个ParameterBagPOST参数.

  • *`ParameterBag`,它有`all()`方法来获取包含所有包含参数的数组. (2认同)