我有一个带有可选参数的路由:
/**
* @Route( "/route/{id}", name="_route", defaults={"id" = ""} )
* @Template()
*/
在模板中,我有一个表单,我希望将表单发送到:
/route
或者:
/route/10
/route/10/mail – if there were more than just one parameter
目前我是这样解决的:
{{ path(app.request.attributes.get('_route')) }}/{{ object.id }}
哪个工作正常,但我必须自己添加所有可能的参数。有没有办法从 Twig 中获得完整的当前路径?我不想在我的 Controller 中添加一个额外的变量来发送到模板。
最佳答案
Request
类(class)有 getRequestUri()
方法。您可以在 Twig 中访问它
{{ app.request.requesturi }}
关于Symfony2 + Twig 获得真实/完整的当前路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11137265/