Php 是否有方法获取URL引用的模块/操作?

Php 是否有方法获取URL引用的模块/操作?,php,symfony1,routes,reverse,Php,Symfony1,Routes,Reverse,在symfony中,是否有一种方法可以用于反向查找路由,以确定URL指向的模块和操作 比如说: get_module("http://host/cars/list"); // ("cars") get_action("http://host/frontend_dev.php/cars/list"); // ("list") 请记住,我不想执行简单的字符串攻击来实现这一点,因为可能存在不太明显的映射: get_module("/"); // (What this returns is enti

在symfony中,是否有一种方法可以用于反向查找路由,以确定URL指向的模块和操作

比如说:

get_module("http://host/cars/list"); // ("cars")
get_action("http://host/frontend_dev.php/cars/list"); // ("list")
请记住,我不想执行简单的字符串攻击来实现这一点,因为可能存在不太明显的映射:

get_module("/");  // (What this returns is entirely dependent on the configured routes.)

谢谢

使用sfRouting类匹配URL。这是sfContext对象的一部分。您的代码(在操作中)如下所示:

public function executeSomeAction(sfWebRequest $request)
{
  if($params = $this->getContext()->getRouting()->parse('/blog'))
  {
     $module = $params['module']; // blog
     $action = $params['action']; // index
     $route  = $params['_sf_route'] // routing instance (for fun)
  }
  else
  {
     // your URL did not match
  }
}

在freenode上的#symfony中,我注意到symfony在满足请求时基本上已经做到了这一点!似乎根本就没有最好的方法自己获取这些信息。可能类似于$context->getRouting()->match('url')?关于这个问题,我已经打开了以下票据:虽然这不是100%我的解决方案,但这非常接近,并且可能会尽可能接近,直到他们在symfony API中做出一些东西为止。