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?
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>'
);
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>'
);
Another option is via Request::create
method.
Request::create(
'<uri>',
'<method>',
<parameters>,
<cookies>,
<files>,
<server>,
'<your-content>'
);
Source: HTTP foundation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With