Php 如何从symfony中的URL猜出操作名和模块名?

Php 如何从symfony中的URL猜出操作名和模块名?,php,symfony1,routing,Php,Symfony1,Routing,例如,我有一个参考URL。我想根据上一页的模块重定向到一个页面。上有一个代码片段。要获取上一页的模块和操作,您将使用referer: $referer = sfContext::getInstance()->getRequest()->getReferer(); // you have to check if the referer is not empty and is a page of your site .... // then get the

例如,我有一个参考URL。我想根据上一页的模块重定向到一个页面。

上有一个代码片段。要获取上一页的模块和操作,您将使用referer:

    $referer = sfContext::getInstance()->getRequest()->getReferer();
    // you have to check if the referer is not empty and is a page of your site
    ....
    // then get the module and action:
    $url = parse_url($referer);
    $path = trim($url['path'], '/');
    if (!sfConfig::get('sf_no_script_name') && $pos = strpos($path, '/') )
    {
        $path = substr($path, $pos+1);
    }
    $params = sfContext::getInstance()->getRouting()->findRoute('/'.$path);
    $module = $params['parameters']['module'];
    $action = $params['parameters']['action'];