简体   繁体   English

树枝:如何获取请求字符串?

[英]twig: How to get request string?

I have a url: http://myserver.com/mypage?vid=1234我有一个网址: http : //myserver.com/mypage? vid= 1234

I want to output 1234 on to the page.我想将 1234 输出到页面上。 I have tried this but it is not working:我试过这个,但它不起作用:

{{ app.request.get('vid') }}

what am I doing wrong or missing?我做错了什么或错过了什么?

You can do this by using the "query" object :您可以通过使用“查询”对象来做到这一点:

{{ app.request.query.get('vid') }}

But you should get this value in the controller and then pass it to twig.但是您应该在控制器中获取此值,然后将其传递给 twig。

EDIT : This answer is based on the asumption that you are using Symfony Framework编辑:此答案基于您使用 Symfony 框架的假设

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

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