Question

Is there a reason to use Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) rather than Mage::getBaseUrl()? I've seen both in use, and they both return the same thing. Is the longer one redundant? It uses 2 function calls, as well.

Moreover, I see that Mage_Core_Model_Store::URL_TYPE_WEB simply returns the string 'web'. What's the point of it?

Was it helpful?

Solution

First look at getBaseUrl() at Mage.php

 public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
    {
        return self::app()->getStore()->getBaseUrl($type, $secure);
    }

In a simple word we can say:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) indicated Your Magento Site Url from this url Magento is running it System.

And other word ,we can say that Mage::getBaseUrl() give the url which is linking your magento internal page urls That MVC page

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB):

Value Set at : From Admin>System>Configuration>WebSite>Secure/Unsecure -> Base url

Mage::getBaseUrl():

Value Set at : From Admin>System>Configuration>WebSite>Secure/Unsecure -> Base Link url

Main Difference Showing:

Whenever we are enable Use Web Server Rewrites = no from admin>system>Web>Search Engines Optimization Rewrites

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) give the value of http://youdomain/

but Mage::getBaseUrl() give value http://youdomain/index.php/ that actually give the value of Mage_Core_Model_Store::URL_TYPE_LINK

when you hit http://youdomain/ that is call Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) url But that times you can see all pagelink of your site is starting with http://youdomain/index.php/ that means it taken Mage::getBaseUrl()/ Mage::getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)

Example:

If you have create a folder amit at Magento root dir and there you have put a file test.js then you want to call this file at magento home then you can use this code

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'amit/test.js'; ?>

and it give then url

www.yourdomain/amit/test.js

If You use only Mage::getBaseUrl() which give u www.yourdomain/index.php/amit/test.js that mean test.js cannot accessible (when rewite disable)

But you have create new controller and new action then you can use

Mage::getBaseUrl().'yourmodulerouter/yourcontroller/youraction'

it show  url like `http://yourdomain/index.php/yourmodulerouter/yourcontroller/youraction`

or give http://yourdomain/yourmodulerouter/yourcontroller/youraction(when rewrite enable)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top