symfony2 render controller with get parameters

10,703

Solution 1

In accordion with the doc the query argument is the third parameters.

{{ controller(controller, attributes, query) }}

So try this:

{{ render(controller('AutoBundle:MyController:main', {}, { 'id': id, 'active': true } )) }}

Hope this help

Solution 2

Yes, it doesn't send the parameters as a GET request, but seems to call the method directly.

Twig template part:

<div id="question-choose-semester">
    {{ render(controller('UnswCamsBundle:Semester:choiceAjax', { 'redirect':  path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params'))} )) }}
</div>

Create an optional parameter. If using annotations to define the route, you don't have to add it to the annotation specification.

  public function choiceAjaxAction($redirect = "", Request $request) {

Then check the GET parameter:

if (empty($redirect)) {
  $redirect_uri = $request->query->get('Redirect');
} else {
Share:
10,703
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    How to render a controller with get parameters in twig?

    {{ render(controller('AutoBundle:MyController:main', { 'id': id, 'active': true } )) }}
    

    to call controller like this: https://example.com/users/323?active=true