如何在symfony2中获取请求的路径 [英] How to get the path of the request in symfony2
问题描述
我知道方法 \Symfony\Component\HttpFoundation\Request :: getPathInfo()
,但是在文档中指出,该方法仅返回相对于已执行脚本的请求路径。如何获取完整路径?第二点,当所有请求都通过前端控制器时,已执行脚本是什么意思?
I know of the method \Symfony\Component\HttpFoundation\Request::getPathInfo()
however in the docs it states that, that only returns the path of the request which is "relative" to the "executed script".How can I get the full path?and on a second note what does 'executed script' mean when all requests are going through the front controller?
推荐答案
$ request-> getUri()
返回绝对URL => http://example.com/app.php/path
$request->getUri()
returns the absolute URL => http://example.com/app.php/path
$ request-> getRequestUri()
返回绝对路径=> /app.php/path
$request->getRequestUri()
returns the absolute path => /app.php/path
$ request-> getPathInfo()
返回与控制器操作对应的路径=> / path
$request->getPathInfo()
returns the path corresponding to your controller's action => /path
getPathInfo
只是从请求URI中减去已执行的脚本(/app.php),因此它返回相对于已执行的路径脚本。
getPathInfo
just subtracts the executed script (/app.php) from the request URI, so it returns the path relative to the executed script.
这篇关于如何在symfony2中获取请求的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!