Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass all request query parameters to embedded controllers in twig symfony 2?

Tags:

php

twig

symfony

{{ render(controller("SomeBundle:Foo:Bar", {HERE I WANT TO PASS ALL query parameters app.request.query.all}) }}

So can I access all master request query parameters in sub request and the subrequest should also run independently?

like image 999
vishal Avatar asked Feb 10 '14 06:02

vishal


2 Answers

Try this:

{{ render(controller("SomeBundle:Foo:bar", {'all': app.request.query.all}) }}

and in action store it in $all variable

public function barAction($all) {
    // other your code
}
like image 155
Victor Bocharsky Avatar answered Sep 22 '22 17:09

Victor Bocharsky


From your controller:

array_merge($request->query->all(), $request->get('_route_params'));

//query->all : get all query string parameters
//_route_params : get current route parameters

From your twig template must be sth like:

app.request.query.all|merge(app.request.attributes.get('_route_params'))

I've never used this in twig templates, so first test it ;)

Then you can use that functions however you want to build the variables you'll pass to your subrequest

like image 45
jdharandas Avatar answered Sep 21 '22 17:09

jdharandas