Reputation: 12306
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?
Upvotes: 12
Views: 8649
Reputation: 483
Another dirty solution with usage of closures: https://www.php.net/manual/en/closure.call.php
$requestClosure = function() use ($decryptedJson) {
$this->content = $decryptedJson;
return $this;
};
$request = $requestClosure->call($request);
How this works:
$this
becomes the request itself so it's possible to call private content
,return $this
in closure returns the $request
in context of which the call was made,Upvotes: 0
Reputation: 934
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>'
);
Upvotes: 6
Reputation: 4518
Another option is via Request::create
method.
Request::create(
'<uri>',
'<method>',
<parameters>,
<cookies>,
<files>,
<server>,
'<your-content>'
);
Source: HTTP foundation
Upvotes: 2
Reputation: 2929
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>'
);
Upvotes: 9