2012-05-24 28 views
23

Tôi muốn lấy tất cả các thông số của một biểu mẫu của symfony.Làm thế nào để có được tất cả các thông số bài trong Symfony2?

tôi đã sử dụng:

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

và tôi nhận được lỗi này

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

Trong trường hợp một số người đang tìm kiếm symfony 3: $ request = Request :: createFromGlobals(); $ a = $ request-> request-> all() –

Trả lời

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

Khi 'Yêu cầu $ request' là tham số cho hành động điều khiển:' $ request-> request-> all() ' – jmq

+2

Tôi nghĩ' $ this-> get ('request') 'không được dùng nữa trong phiên bản 2.8 và đã bị loại bỏ trong 3.0. Không xác nhận. Dù sao, các bình luận @jmq đóng đinh nó. –

9

Symfony Request Objects có khá một vài thuộc tính công cộng mà đại diện cho các phần khác nhau của yêu cầu. Có lẽ là cách dễ nhất để mô tả nó là để cho bạn mã cho 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; 
} 

Vì vậy, như bạn thấy, Request::$request là một ParameterBag các thông số POST.

+2

* 'ParameterBag', có phương thức' all() 'để lấy một mảng với tất cả các tham số chứa. –

+0

* 'ParameterBag', có phương thức' all() 'để lấy một mảng với tất cả các tham số chứa. –

Các vấn đề liên quan