Magento comes with built in function for retrieving URL paths. Function is called getBaseUrl() and its located under Mage class. However, function is not documented as it should be. Documentation only states that function retrieves $type parametar which is by default equal to “base”.
Here is the list of all the available parameters I found. As you can see, they all come from Mage_Core_Model_Store.
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
// http://example.com/js/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
// http://example.com/index.php/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
// http://example.com/media/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
// http://example.com/skin/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
// http://example.com/
Where http://example.com/ is the url of your site. If you don’t provide any parameters to getBaseUrl() function you would retrieve the same path as with URL_TYPE_LINK parametar.
Remember, you need to echo out these statements to the browser, because they each return a string, so you need to output that string like
Leave a Reply