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

anybody have idea ?


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;

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

| improve this answer | |

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