How to Get Base, Media, Skin & Link URL in Magento2?

  • Posted by Envision Ecommerce
  • /
  • May 2, 2016
How-to-get-base-URL-in-Magento2.jpg May 2, 2016 128 kB 1024 × 600 Edit Image Delete Permanently URL http://demo.envisionecommerce.com/wp-content/uploads/2016/05/How-to-get-base-URL-in-Magento2.jpg Title How-to-get-base-URL-in-Magento2 Caption
It is different to get a URL in Magento 2 while comparing it with Magento 1.x. In Magento 1.x, Mage::getBaseUrl() is used to get the base URL. However, Magento 2 supports different methods to get the base, media, skin and link URL. Here is the blog that is going to make clear how you can get the URL in Magento 2.0:

1) To Get Base URL:-

$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore($storeId)->getBaseUrl();

$this->_storeManager->getStore()->getBaseUrl();

2) To Get Url for Link:-

$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);

3) To Get Media Base Url:-

$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);

4) To Get Skin URl:-

$block->getViewFileUrl();

For admin interface:-

{{view url=''}}