Retrieving URL paths in magento

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);
/**Output**//
      http://magesite.extension/js/
 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
/**Output**//
      http://magesite.extension/index.php/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
/**Output**//
      http://magesite.extension/media/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
/**Output**//
      http://magesite.extension/skin/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
/**Output**//
      http://magesite.extension/ 

Where http://magesite.extension/ 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

<?php
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
?>
Advertisements

Tagged: ,

One thought on “Retrieving URL paths in magento

  1. hmm...? October 13, 2010 at 3:37 pm

    thanks

Comments are closed.

%d bloggers like this: