2012-05-24 6 views
23

심포니 폼의 모든 게시 매개 변수를 가져오고 싶습니다.Symfony2에서 모든 post 매개 변수를 얻는 방법은 무엇입니까?

내가 사용 :

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

내가 요청의 다른 부분을 나타냅니다 꽤 많은 공용 속성을 가지고 심포니 Request Objects이 오류를

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

일부 사용자가 심포니 3을 검색하는 경우 : $ request = Request :: createFromGlobals(); $ request-> request-> all() –

답변

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

'Request $ request'가 컨트롤러 액션을위한 매개 변수 일 때 :'$ request-> request-> all()' – jmq

+2

'$ this-> get ('request')'는 2.8에서 사용되지 않으며 3.0에서 제거되었습니다. 확인하지 못했습니다. 어쨌든 @jmq 주석이 그것을 못 박았습니다. –

9

를 얻을. 당신이 볼 수있는 아마 그것을 설명하는 가장 쉬운 방법은 Request::$request는 POST 매개 변수의 ParameterBag이다, 그래서 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; 
} 

당신에게 코드를 보여주는 것입니다.

+2

*'ParameterBag', 모든 포함 된 매개 변수를 가진 배열을 얻기위한'all()'메소드가 있습니다. –

+0

*'ParameterBag', 모든 포함 된 매개 변수를 가진 배열을 얻기위한'all()'메소드가 있습니다. –

관련 문제