Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all post parameters in Symfony2? [duplicate]

Tags:

php

symfony

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
like image 590
Akrramo Avatar asked May 24 '12 13:05

Akrramo


2 Answers

$this->get('request')->request->all()
like image 163
Mun Mun Das Avatar answered Nov 02 '22 00:11

Mun Mun Das


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.

like image 28
Peter Bailey Avatar answered Nov 02 '22 01:11

Peter Bailey