Sunday, 20 November 2011

How to get some important url in magento

In the day-to-day development Magento developer needs some important url quite handy.

//  =>Gives current url of the page
$currentUrl = $this->helper('core/url')->getCurrentUrl();

// =>Gives the base url of your magento installation
$baseUrl = Mage::getBaseUrl();

// =>Also interpreted as below:

$storeUrl = Mage::getBaseUrl();
$storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

// =>Gives the url of media directory inside your magento installation
$mediaUrl = Mage::getBaseUrl('media');

// =>Another way to get current url
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');

//=> Getting base directory of magento
$baseDir= Mage::getBaseDir();

//=> Getting media directory path
$baseDir= Mage::getBaseDir('media');

// ==> Skin url
$imageUrl= $this->getSkinUrl('images/your_image.jpg'); 
$imageUrl= Mage::getDesign()->getSkinUrl('images/your_image.jpg'); 
// ==> Skin secure url
$imageUrl= $this->getSkinUrl('images/your_image.jpg', array('_secure'=>true));
$imageUrl= Mage::getDesign()->getSkinUrl('images/your_image.jpg', array('_secure'=>true));

Here is some important url style if you using in the static block and cms pages

Base Url :

{{store url=""}}

Skin Url :

{{skin url='images/imagename.jpg'}}

Media Url :

{{media url='/imagename.jpg'}}

Store Url  +  html page:

{{store url='mypage.html'}} 

No comments :

Post a Comment