Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 render controller with get parameters

Tags:

php

twig

symfony

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

like image 386
Nikola Dragic Avatar asked Aug 24 '15 08:08

Nikola Dragic


2 Answers

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

like image 98
Matteo Avatar answered Nov 08 '22 12:11

Matteo


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 {
like image 2
Interlated Avatar answered Nov 08 '22 12:11

Interlated