2012-05-24 16 views
23

Symfony Formunun tüm post parametrelerini almak istiyorum.Symfony2'deki tüm posta parametreleri nasıl alınır?

kullandığım:

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

ve istek farklı bölümlerini temsil epeyce kamu özelliklere sahip Symfony'nin Request Objects bu hatayı

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

$ a = $ request-> request-> all() –

cevap

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

'Request $ request' denetleyici eylemi için bir parametre olduğunda:' $ request-> request-> all() ' – jmq

+2

Sanırım bu $> get ('request') '2.8'de kullanımdan kaldırıldı ve 3.0'da kaldırıldı. Onaylamadı. Her neyse, jmq yorumu bunu çiviledi. –

9

olsun. Gördüğünüz gibi Muhtemelen bunu açıklamak için en kolay yolu Request::$request POST parametrelerinin ParameterBag olduğunu, Yani 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; 
} 

için size kodu göstermektir. Bazıları 3 için arama yapıyorsa: $ request = Request :: createFromGlobals();

+2

* Tüm parametrelerle bir dizi elde etmek için all() 'yöntemine sahip' 'ParameterBag'. –

+0

* Tüm parametrelerle bir dizi elde etmek için all() 'yöntemine sahip' 'ParameterBag'. –

İlgili konular