有没有一种方法可以获取URL所指的模块/动作?

| 在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
  }
}
    

要回复问题请先登录注册