简体   繁体   English

symfony2使用get参数渲染控制器

[英]symfony2 render controller with get parameters

How to render a controller with get parameters in twig? 如何使用twig中的get参数渲染控制器?

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

to call controller like this: https://example.com/users/323?active=true 像这样调用控制器: https//example.com/users/323?active = true

In accordion with the doc the query argument is the third parameters. doc一起 ,查询参数是第三个参数。

{{ controller(controller, attributes, query) }} {{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. 是的,它不会将参数作为GET请求发送,但似乎直接调用该方法。

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: 然后检查GET参数:

if (empty($redirect)) {
  $redirect_uri = $request->query->get('Redirect');
} else {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM