说,我有一个 URL http://server/mysite/web/app_dev.php/resource/1
。我正在做一个GET
请求,相应的操作是ResourceController::getAction
.
在这个控制器动作中,如果我打电话$request->getPathInfo()
,它会给我/resource/1
。
但是在同一个控制器中,如果我使用另一个资源的 url 创建一个 Request 对象并调用getPathInfo()
它会返回一个更长的版本。
$request = Request::create('http://server/mysite/web/app_dev.php/another_resource/1');
echo $request->getPathInfo();
OUTPUT >>
/mysite/web/app_dev.php/another_resource/1
只有在这种情况下才能getPathInfo()
退货?/another_resource/1
或者
任何人都可以建议在 Symfony2 中将端点 URL 转换为最安全的方法是什么http://server/mysite/web/app_dev.php/another_resource/1
?/another_resource/1
如果你有兴趣知道我为什么需要这个
控制器操作正在接收请求内容中的一些 URL。该操作需要解析这些 URL 以识别相应的资源。我正在尝试使用$router->match
函数从 URL 中检索参数。match 函数只需要/another_resource/1
部分。