I understand that using {% render() %}
automatically forces a new request object to be sent, but im curious if theres a way to pass in the originating request as an argument?
{% render('some_action', {'originalRequest': app.request}) %}
This doesn't seem to do anything for the controller:
public function actionAction($originalRequest = null)
{
// $originalRequest ends up just being null
}
Im assuming its because of the way the route is setup:
some_action:
pattern: /stuff/
defaults: { _controller:SomeApp:Controller:action }
I'd imagine data like that cant obviously be apart of the URL, so some type of way to pass in data to a renderable URL, anything at all?
EDIT (Solution)
The solution was pretty simple in the long run, as Petre Pătraşc below has demonstrated, that in Twig, all I needed to do was invoke the Controller directly, and with that approach I can pass in Objects (Such as a Request object) and Arrays, instead of text values in a URL.
To perform roughly the same idea in a controller, utilizing the forward()
method from the router, will allow similar effects without needing to redirect the user to another page.
If I understand correctly, you're looking for this:
{% render "MyBundle:Controller:someAction" with { 'originalRequest' : app.request } %}
use the render function as a result
{{ render(controller('MyBundle:ControllerName:example', {'originalRequest': app.request})) }}
and then in your controller
public function exampleAction(Request $originalRequest)
{
// do something
}
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