7

How to get Configuration->Web->Base URLs -> Base URL in multi store magento 2. I have enabled Add Store Code to Urls

I have use on phtml page but it return me url with store code and I need only base url without store code:

<?php echo $block->getBaseUrl();?>

Output of above code is www.example.com/de and my requirement is www.example.com

This is magento1 code.

Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_UNSECURE_URL);

I need it in magento 2.

4

I have found solution. Bellow is my code.

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue("web/unsecure/base_url");?>

Thanks.

  • 1
    This works, but please don't use the ObjectManager. Inject the class Magento\Framework\App\Config\ScopeConfigInterface into the constructor, assign it to a class variable and use it from there. – Andreas von Studnitz Oct 6 '17 at 7:19
1

Use below code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
  • i have check your solution but it still give result www.example.com/de. – Jalpesh Patel Dec 13 '16 at 9:19
  • thanks for help. now i found solution.I have added my solution in answer – Jalpesh Patel Dec 13 '16 at 9:29
  • In my case I used this one $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB) – embed0 May 6 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.