B-219 Sec-55 Noida, India
+918010221733

Magento Application some useful functions we used in development

Sometimes we need to check the current host name in magento. Here is the function that returns the hostname of server where the application is executing.

The following code is same as normal PHP $_SERVER[‘HTTP_HOST’]

<?php      echo Mage::app()->getFrontController()->getRequest()->getHttpHost();?>

 It returns 127.0.0.1 if we runs on 127.0.0.1 or in other cases it returns the domain name of the site.
 When we want to retrieve the Path of Base Directory in Magento. We can use the following function

 <?php echo Mage::getBaseDir();  //gives  physical path of the sites root directory ?>

(In my case it return e:wwwmagento )

Its returns the Physical path of the Application directory where magento application installed.
When we want to retrieve the relative path of the sites default skin folder. IT return the virtual path of the default skin folder. Many time we used in theme development

 <?php echo $this->getSkinURL(); ?>

 It returns the http://127.0.0.1/www/magento/skin/frontend/default/default/
Virtual path of the magneto application can be retrieved with the following function. Relative path of the Magento site

<?php echo Mage::getBaseURL();   ?>
Or
<?php echo Mage::getURL();?>

(Visited 70 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.