To get URL in magento2, you have to first create instance of \Magento\Framework\App\ObjectManager to get current store:
1 2 3 |
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //instance of\Magento\Framework\App\ObjectManager $storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface'); $currentStore = $storeManager->getStore(); |
To get base URL:
1 2 3 |
$baseUrl = $currentStore->getBaseUrl(); //Output link will be like this: //http://magento2.webkul.com/marketplace |
To get media base URL:
1 2 3 |
$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); //Media url output link will be like this: //http://magento2.webkul.com/marketplace/pub/media |
To get link base url:
1 2 3 |
$linkUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); //Output link will be link this: //http://magento2.webkul.com/marketplace |
2 comments