简体   繁体   English

如何在Symfony 3.4中获取当前页面的URL

[英]How to get the current page URL in Symfony 3.4

I mean is how can I get the current relative URL, including the file name if there is one, ie everything emphasized below: 我的意思是,如何获取当前的相对URL,包括文件名(如果有的话),即下面强调的所有内容:

http://hostname/app/app_dev.php/path/to/some/action?even=a%20query%20string
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I tried like 我试过像

$request->getRequestUri();

but I'm getting the result like this 但我得到这样的结果

http://hostname/app/app_dev.php/admin/get

I want result like this 我想要这样的结果

http://hostname/myproject_name/user/method/action

How to get in Symfony 3.4 如何获得Symfony 3.4

This represents the base URL of the current request prefixed by the path of the current request. 这表示当前请求的基本URL,并以当前请求的路径为前缀。 Also it doesn't return URL's query string: 而且它不返回URL的查询字符串:

$request->getSchemeAndHttpHost().$request->getPathInfo()

For example for this real URL: 例如,此真实URL:

http://127.0.0.1:8001/app_dev.php/homepage?page=3&size=20

above snippet will return: 以上代码段将返回:

http://127.0.0.1:8001/homepage

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

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