Magento Resource | E-Commerce Generation Explorer

Jun/09

29

Retrieving URL paths in Magento

As we know, Magento comes with built in function for retrieving URL paths. Function is called getBaseUrl() and its located under Mage class.

But this 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 which they had, and they all come from Mage_Core_Model_Store.
•Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
http://magesite.extension/js/
•Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
http://magesite.extension/index.php/
•Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
http://magesite.extension/media/
•Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
http://magesite.extension/skin/
•Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
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 parameter.

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

1
2
3
<?php
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
?>

ENJOY!

· ·

2 comments

  • Rajesh Bhatia · 16/04/2010 at 13:52

    Thanks for your post.. 🙂

  • Prateek · 29/06/2010 at 13:35

    Hey, I have the images (say bc.gif) in the /app/code/local/Sample/Sample1/images/bc.gif and i have my code in /app/code/local/Sample/Sample1/Block/sample.php I have my javascript and css also in the (/app/code/local/Sample/Sample1/css/custom.css) and so is the js. I am unable to access the css, js and images through the sample.php file. Please help.

Leave a Reply

<<

>>

Theme Design by devolux.nh2.me