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
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
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 {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With