Magento删除参数并重定向到同一url

Magento删除参数并重定向到同一url,magento,Magento,我想删除一些URL参数(比如utm_source,但不管怎样),将其放入会话中,并重定向到同一个页面,URL清除这个特定参数 我以前在controller_front_init_中这样做过: $frontController = $observer->getEvent()->getFront(); $params = $frontController->getRequest()->getParams(); $myParams = array("b"); foreach($

我想删除一些URL参数(比如utm_source,但不管怎样),将其放入会话中,并重定向到同一个页面,URL清除这个特定参数

我以前在controller_front_init_中这样做过:

$frontController = $observer->getEvent()->getFront();
$params = $frontController->getRequest()->getParams();
$myParams = array("b");
foreach($myParams as $myParam) {
    if (isset($params[$myParam])) {
        $customerSession->setData(
            $myParam, $params[$myParam]
        );
        unset($params[$myParam]);
    }
}
$frontController->getRequest()->setParams($params); // <- I don't know what to do with that
$frontController=$observer->getEvent()->getFront();
$params=$frontController->getRequest()->getParams();
$myParams=数组(“b”);
foreach($myParams作为$myParam){
if(isset($params[$myParam])){
$customerSession->setData(
$myParam,$params[$myParam]
);
未设置($params[$myParam]);
}
}

$frontController->getRequest()->setParams($params);//是的,$shouldRedirect标志是必要的,否则它将循环,我注意到。我认为有一种方法可以获取当前reuqest url的实例,设置新参数并重定向,而不需要使用Mage::getUrl()构造新的
$frontController = $observer->getEvent()->getFront();
$params = $frontController->getRequest()->getParams();
$shouldRedirect = false

foreach($params as $key => $value) {
    if ($key !== 'b') {
        $customerSession->setData($key, $value);   
    }
    else{
       unset($params[$key]);
       $shouldRedirect = true;
    }
}

if($shouldRedirect){
    //$url = get url and redirect
    //see http://magento.stackexchange.com/questions/5000/add-query-parameters-to-an-existing-url-string
    Mage::app()->getResponse()->setRedirect($url);       
}