2012-05-24 20 views
23

Voglio ottenere tutti i parametri del post di un modulo symfony.Come ottenere tutti i parametri del post in Symfony2?

ho usato:

$all_parameter = $this->get('request')->getParameterHolder()->getAll(); 

e ottengo questo errore

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 
+0

Nel caso in cui alcuni siano in cerca di symfony 3: $ request = Request :: createFromGlobals(); $ a = $ request-> request-> all() –

risposta

76
$this->get('request')->request->all() 
+14

Quando 'Request $ request' è un parametro per l'azione del controller:' $ request-> request-> all() ' – jmq

+2

Penso che $ this-> get ('request') 'è deprecato in 2.8 ed è stato rimosso in 3.0. Non ha confermato Ad ogni modo, il commento di @jmq lo ha inchiodato. –

9

Symfony Request Objects avere un bel paio di proprietà pubbliche che rappresentano diverse parti della richiesta. Probabilmente il modo più semplice per descriverlo è quello di mostrare il codice per 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; 
} 

Quindi, come potete vedere, è un Request::$requestParameterBag dei parametri POST.

+2

* 'ParameterBag', che ha il metodo' all() 'per ottenere un array con tutti i parametri contenuti. –

+0

* 'ParameterBag', che ha il metodo' all() 'per ottenere un array con tutti i parametri contenuti. –

Problemi correlati