Php $request->;getPathInfo()为';返回相同的字符串;产品';和';开发和#x27;环境
我正在使用Php $request->;getPathInfo()为';返回相同的字符串;产品';和';开发和#x27;环境,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我正在使用$request->getPathInfo()在操作中设置当前url。然而,检索到的url始终是prod环境的url,这意味着在测试期间我无意地从dev移动到prod环境 是否仍然可以确保返回正确的URI(即与浏览器窗口中显示的URI相同) 我的操作代码如下所示: public function executeSomeAction(sfWebRequest $request) { $this->url = $request->getPathInfo(); } 正如
$request->getPathInfo()
在操作中设置当前url。然而,检索到的url始终是prod环境的url,这意味着在测试期间我无意地从dev移动到prod环境
是否仍然可以确保返回正确的URI(即与浏览器窗口中显示的URI相同)
我的操作代码如下所示:
public function executeSomeAction(sfWebRequest $request)
{
$this->url = $request->getPathInfo();
}
正如您在
sfWebRequest.class.php
中看到的,getPathInfo()
从url中删除了$relativeUrlRoot
:
$pathInfo = $pathArray[$sf_path_info_key];
if ($relativeUrlRoot = $this->getRelativeUrlRoot())
{
$pathInfo = preg_replace('/^'.str_replace('/', '\\/', $relativeUrlRoot).'\//', '', $pathInfo);
}
$relativeUrlRoot
来自此函数,它从url中删除控制器名称
public function getRelativeUrlRoot()
{
if (null === $this->relativeUrlRoot)
{
if (!($this->relativeUrlRoot = $this->getOption('relative_url_root')))
{
$this->relativeUrlRoot = preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName());
}
}
return $this->relativeUrlRoot;
}
因此,如果您有myapp\u dev.php/main
或index.php/main
,您将始终获得/main
如果要在/main
之前获得完整路径,还必须调用$this->request->getScriptName()
小心,
getScriptName()
将返回域和路径信息之间的所有内容。如果您有http://exemple.com/somepath/app_dev.php/main
,getScriptName()
将返回:/somepath/app_dev.php
如您在sfWebRequest.class.php
中所见,getPathInfo()
从url中删除了$relativeUrlRoot
:
$pathInfo = $pathArray[$sf_path_info_key];
if ($relativeUrlRoot = $this->getRelativeUrlRoot())
{
$pathInfo = preg_replace('/^'.str_replace('/', '\\/', $relativeUrlRoot).'\//', '', $pathInfo);
}
$relativeUrlRoot
来自此函数,它从url中删除控制器名称
public function getRelativeUrlRoot()
{
if (null === $this->relativeUrlRoot)
{
if (!($this->relativeUrlRoot = $this->getOption('relative_url_root')))
{
$this->relativeUrlRoot = preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName());
}
}
return $this->relativeUrlRoot;
}
因此,如果您有myapp\u dev.php/main
或index.php/main
,您将始终获得/main
如果要在/main
之前获得完整路径,还必须调用$this->request->getScriptName()
小心,
getScriptName()
将返回域和路径信息之间的所有内容。如果您有http://exemple.com/somepath/app_dev.php/main
,getScriptName()
将返回:/somepath/app_dev.php
如果您想要完整的URI以及地址可能包含的任何查询字符串,您可以使用它
$request->getUri();
这将返回在浏览器地址栏中可见的整个地址。如果您想要完整的URI以及地址可能具有的任何查询字符串,则可以使用
$request->getUri();
这将返回浏览器地址栏中可见的整个地址