If you’ve ever needed to fetch header information in Magento, it’s quite a pain. The good news is that Magento gives you some helpers that makes all of it pretty easy. Working with URLs is a topic all of it’s own, but Magento provides a couple of nifty methods in it’s URL helper to help manipulate parameters inside of your URL.
Header Information
These methods are located in Mage_Core_Helper_Http .
1 2 3 4 5 6 7 8 9 |
Mage::helper('core/http')->getHttpHost(); Mage::helper('core/http')->getHttpUserAgent(); Mage::helper('core/http')->getRequestUri(); Mage::helper('core/http')->getServerAddr(); Mage::helper('core/http')->getRemoteAddr(); |
URLs
These methods are located in Mage_Core_Helper_Url .
1 2 3 4 5 |
Mage::helper('core/url')->getCurrentUrl(); Mage::helper('core/url')->addRequestParam($url, array('id', '25')); Mage::helper('core/url')->removeRequestParam($url, 'id'); |
Always remember, before you go an try creating a method yourself, see if Magento already did it for you. There are some amazing things inside the system and you’ll always be pleasantly surprised by what you will find.
Love it? Hate it? Want more? Leave me a comment and let me know!