vishal
vishal

Reputation: 4083

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

{{ 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?

Upvotes: 7

Views: 9030

Answers (3)

lukeocodes
lukeocodes

Reputation: 1232

To just pass in what is in app.request.query.all:

{{ render(controller("SomeBundle:Foo:Bar", app.request.query.all)

To merge something extra in:

{{ render(controller("SomeBundle:Foo:Bar", { something: 'extra' }|merge(app.request.query.all))

Tested in Symfony 3.3.10 and Twig 1.35.0

Upvotes: 2

jdharandas
jdharandas

Reputation: 526

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

Upvotes: 4

Victor Bocharsky
Victor Bocharsky

Reputation: 12306

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
}

Upvotes: 6

Related Questions