how to pass all request query parameters to embedd

2019-06-22 05:23发布

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

标签: php symfony twig
3条回答
【Aperson】
2楼-- · 2019-06-22 05:45

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

查看更多
放我归山
3楼-- · 2019-06-22 05:49

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
}
查看更多
Luminary・发光体
4楼-- · 2019-06-22 06:03

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

查看更多
登录 后发表回答