Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I set content of request symfony?

I generate manually request content of my form and want to set data like:

form[1][]=2&form[2][]=3&form[3][]=5&form[4][]=8&form[apply]=

The Symfony Request object has an getContent() method, but hasn't setContent().

How can I set content alternatively?

like image 331
Victor Bocharsky Avatar asked Sep 08 '14 06:09

Victor Bocharsky


3 Answers

Found a solution which is dirty but seems to work for me. Just reinitialize the request.

    $request->initialize(
        $request->query,
        $request->request,
        $request->attributes,
        $request->cookies,
        $request->files,
        $request->server,
        '<your-content>'
    );
like image 88
sebbo Avatar answered Sep 17 '22 18:09

sebbo


Symfony 4 > version:

$request->initialize(
    $request->query->all(),
    $request->request->all(),
    $request->attributes->all(),
    $request->cookies->all(),
    $request->files->all(),
    $request->server->all(),
    'your-content>'
);
like image 26
Luke Duda Avatar answered Sep 17 '22 18:09

Luke Duda


Another option is via Request::create method.

Request::create(
   '<uri>', 
   '<method>', 
   <parameters>, 
   <cookies>, 
   <files>, 
   <server>, 
   '<your-content>'
);

Source: HTTP foundation

like image 24
Aldee Avatar answered Sep 21 '22 18:09

Aldee