1
例如,我有一個引用URL。我想根據上一頁的模塊重定向到一個頁面。如何從symfony中的URL中猜測動作名稱和模塊名稱?
例如,我有一個引用URL。我想根據上一頁的模塊重定向到一個頁面。如何從symfony中的URL中猜測動作名稱和模塊名稱?
有一個this page的代碼片段。要獲取上一頁的模塊和動作,請使用引用者:
$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'];
救了我的命:D – JhovaniC