【问题标题】:How to get the path of the request in symfony2如何在 symfony2 中获取请求的路径
【发布时间】:2014-09-01 08:37:59
【问题描述】:

我知道\Symfony\Component\HttpFoundation\Request::getPathInfo() 方法,但是在文档中它指出,这只返回与“执行脚本”“相对”的请求路径。我怎样才能获得完整路径?第二个注意,当所有请求都通过前端控制器时,“执行脚本”是什么意思?

【问题讨论】:

    标签: symfony routing request


    【解决方案1】:

    $request->getUri() 返回绝对 URL => http://example.com/app.php/path

    $request->getRequestUri() 返回绝对路径 => /app.php/path

    $request->getPathInfo() 返回你的控制器动作对应的路径 => /path

    getPathInfo 只是从请求 URI 中减去执行的脚本(/app.php),所以它返回相对于执行脚本的路径。

    【讨论】:

    • GetRequestUrl() 似乎返回了路径和查询参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 2015-05-01
    相关资源
    最近更新 更多