Symfony2:如何获取请求参数 [英] Symfony2: How to get request parameter

查看:36
本文介绍了Symfony2:如何获取请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条路线:

professor_identity_edit:
path:     /professor/{id}/identity
defaults: { _controller: FrontBundle:ProfessorIdentity:edit }

如何获取twig.html文件中的{id}参数?

How can I get the parameter {id} in twig.html file ?

我已经尝试过 app.request.query.get('id') 但没有成功.

I already tried app.request.query.get('id') but with no success.

推荐答案

这不是一件好事,但您仍然可以做到.通常,您会像@Maerlyn 指出的那样,将信息从控制器传递给 Twig.

Not a good thing but you can still do. Normally you would pass the info to Twig from the controller like @Maerlyn pointed out.

在 Twig 中获取路由参数.

Get route parameters in Twig.

{{ app.request.attributes.get('_route_params') }}

在 Twig 中获取整个包名称.

Gets whole bundle name in Twig.

{{ app.request.attributes.get("_controller") }}

在 Twig 中获取路线名称.

Get route name in Twig.

{{ app.request.attributes.get('_route') }}

这篇关于Symfony2:如何获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆