2

In my custom module I have passed parameter in URL like this:

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); ?>
<a href="<?php echo $currentUrl .'?alpha='. $letter ;?>"><?php echo $letter; ?></a>

The problem is that I have used this parameter to filter collection and the result is returned to the same page, everything is working fine. But from result page when another parameter is selected URL became like this:

www.mydomain/category.html?alpha=D?alpha=J

Is it possible to remove the duplicate parameters?

Note: need to remove only duplicates not the other parameters.

  • Can you add the code that set the value for $currentUrl. You need to set currentUrl to the base url without any parameter to prevent it from just appending the new one – Renon Stewart Jul 1 '15 at 14:18
  • @R.S i added the code for current url. – Piyush Jul 1 '15 at 15:17
  • If that is literally your URL, as in you're delimiting the arguments with a ? then you probably won't be able to parse it properly anyway – Robbie Averill Jul 4 '16 at 1:59
1

Instead of getCurrentUrl() you can use the special parameter _current for getUrl() and then override the "alpha" parameter:

<?php $url = Mage::getUrl('', ['_current' => true, '_query' => ['alpha' => $letter]); ?>
<a href="<?php echo $url ;?>"><?php echo $letter; ?></a>
0

The solution to your issue is to get the base url without any query string (or without that query string).

Mage::helper('core/url')->getCurrentUrl() will return the url with the previous query string and you code above will just append new query sting along with the old one.

Take a look at Magento get current url with and without parameters

$request = $this->getRequest();
$urlWithoutParameters = $this->getBaseUrl() . $request->getRouteName() .DS. $request->getControllerName() .DS. $request->getActionName();
0

you could try to extract your url parts with this: http://php.net/manual/de/function.parse-url.php

and then add your param with this one: http://php.net/manual/de/function.http-build-query.php

finally build your url with: http://php.net/manual/it/function.http-build-url.php

I have to emphasize that this is not really the nice way. You should try to do this with the given magento logic, but since I don't excatly know what you want to do, this should be it ;)

0

Question is too old but this answer may help someone with same requirements. To override current url's parameter you can use this code-

$url = Mage::getUrl('', array('_current' => true,'_use_rewrite' => true, '_query' => $letter));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.