如何在symfony中猜测URL中的动作名称和模块名称?

时间:2012-05-20 08:19:39

标签: php symfony1 routing

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

1 个答案:

答案 0 :(得分:2)

this page上有一段代码段。要获取上一页的模块和操作,您将使用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'];