33

I want to get all post parameters of a symfony Form.

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
AKRAM EL HAMDAOUI
  • 1,818
  • 4
  • 22
  • 27
  • 1
    In case some are searching for symfony 3 : $request = Request::createFromGlobals(); $a = $request->request->all() – Dariux Apr 21 '16 at 07:29

2 Answers2

94
$this->get('request')->request->all()
Mun Mun Das
  • 14,992
  • 2
  • 44
  • 43
  • 20
    When `Request $request` is a parameter for the controller action: `$request->request->all()` – jmq Feb 02 '16 at 20:29
  • 3
    I think `$this->get('request')` is deprecated in 2.8 and was removed in 3.0. Didn't confirm. Anyway, the @jmq comment nailed it. – Rafael Barros Jul 31 '17 at 19:49
9

Symfony Request Objects have 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()

/**
 * 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::$request is a ParameterBag of the POST parameters.

Peter Bailey
  • 105,256
  • 31
  • 182
  • 206