1

I have a url and I want to know the route that it resolves to, I want a function that is the the inverse of url_for - how do I go about this?

Edit: note that the url is different to the current url

cerberos
  • 7,705
  • 5
  • 41
  • 43

1 Answers1

4

You should be able to just use sfPatternRouting::findRoute(). for example:

$routing = sfContext::getInstance()->getRouting(); // or $this->context->getRouting() in an action
if($route = $routing->findRoute($url))
{
  $routeName = $route['name'];
}

if you need to use it in the view then you could make helper like myUrlHelper.php with:

/*
 * Return routing info for an url
 *
 * @param string $url
 * @return Array|Boolean
 */
function route_for($url)
{
  return sfContext::getInstance()->getRouting()->findRoute($url);
}
prodigitalson
  • 60,050
  • 10
  • 100
  • 114