Mage::getBaseUrl() vs Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)

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?


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


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


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)


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


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


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

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

Similar questions

Difference between Mage::getModel('core/email_template_mailer') and Mage::getModel('core/email_template');
What is difference between Mage::getModel('core/email_template_mailer') and Mage::getModel('core/email_template');?
Class 'Mage' not found and include(): Failed opening 'Mage.php' error on Magento
We have some many error lines on httpd error log, about 10-15 errors for every day, on different time: Any error not found related to the issue on Magento logs. Some times some customers cannot be login, is it result of the issue given above? It seems these errors appeared after upgrading EE 1.13.1 to EE 1.14.1 month ago. Followed this one, but we ...
How to override abstract block app/code/core/Mage/Wishlist/Block/Abstract.php and app/code/core/mage/Controller/Abstract.php
In Controller Abstract.php file, I want to override the public function allcartAction() to add one more parameter to $item->addToCart($cart, $isOwner)) ie to change the function as $item->addToCart($cart, $isOwner,$params)) In Block/Abstract.php file I want to modify the public function getWishlistItems() { function to remove the visisbility fil...
./mage mage-setup
I am very new to Magento and new to the upgrade. I have been trying to upgrade Magento 1.7.2 to 1.9.2 via SSH. I've created a localhost stage website before I go live but getting many errors. Starting with: when I try ./mage sync or any other function I get: Please initialize Magento Connect installer by running: ./mage mage-setup Please Help, Than...
What is the difference between Mage:getModel and Mage:getModelInstance?
I am using almost all time Mage:getModel. But surprisingly i found somewhere about Mage:getModelInstance. Can you please tell me where to use Mage:getModelInstance and what is the difference between these two ?
Error Warning: file_put_contents(/var/www/html/var/cache//mage-tags/mage---792_CONFIG): failed to open stream: Permission denied
Magento 2 below the Warning come. Please Help. After changing permissions I got an error "Class Magento\Review\Model\ReviewFactory does not exist" Ok, I fixed above error by deleting generation folder and making static content deploy

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.