【问题标题】:How can I guess action name and module name from URL in symfony?如何从 symfony 中的 URL 猜测动作名称和模块名称?
【发布时间】:2012-05-27 03:58:03
【问题描述】:

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

【问题讨论】:

    标签: php symfony1 routing


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多