I am setting the current url in an action, using $request->getPathInfo()
. However, the url retrieved is always that for the prod environment, which means that I inadvertendly move from dev to prod environment during testing.
Is there anyway to ensure that the correct URI (i.e. same as the one displayed in the browser window) is returned?.
My action code looks like this:
public function executeSomeAction(sfWebRequest $request)
{
$this->url = $request->getPathInfo();
}
As you can see inside sfWebRequest.class.php
, getPathInfo()
removed the $relativeUrlRoot
from the url:
$pathInfo = $pathArray[$sf_path_info_key];
if ($relativeUrlRoot = $this->getRelativeUrlRoot())
{
$pathInfo = preg_replace('/^'.str_replace('/', '\\/', $relativeUrlRoot).'\//', '', $pathInfo);
}
$relativeUrlRoot
is from this function which remove the controller name from the 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;
}
So if you have myapp_dev.php/main
or index.php/main
, you will always get /main
.
If you want the full path before the /main
, you will also have to call $this->request->getScriptName()
.
Be careful, getScriptName()
will return everything between the domain and the path info. If you have http://exemple.com/somepath/app_dev.php/main
, getScriptName()
will return: /somepath/app_dev.php
.