开发者

Symfony route_for function

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: n开发者_开发知识库ote that the url is different to the current url


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜