I was wondering how to use the getBaseUrl()
in controller/helper class..
anybody have idea ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityBased 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();