4

I was wondering how to use the getBaseUrl() in controller/helper class..

anybody have idea ?

0

1 Answer 1

15

Based on the duplicate question, I'm just going to explain how to do it in an helper/controller

First you have to inject the Magento\Store\Model\StoreManagerInterface in your constructor:

protected $_storeManager;

public function __construct(
    ...
    \Magento\Store\Model\StoreManagerInterface $storeManager
) {
    $this->_storeManager = $storeManager;
    parent::__construct(...);
}

Then you can use it whenever you want in your class like this:

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

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