In Magento 1 Mage::getBaseUrl();
, but in Magento 2 I have to pass responsible class object type in constructor.
I don’t have the idea which class I have to pass?
base-urlmagento2url
In Magento 1 Mage::getBaseUrl();
, but in Magento 2 I have to pass responsible class object type in constructor.
I don’t have the idea which class I have to pass?
Best Answer
In magento 2.
If you want to get Base url ,then you can try below code:
Where
$this->_storeManager
instance of\Magento\Store\Model\StoreManagerInterface
this above code will give you result
If you want Base URL without
index.php
See in details at
magento2 get base url and media url and static url
Using Object Manager
Base Url:
Base Url without index.php
For getting media base url:
for getting link url:
Edit
For getting the
$this->_storeManager
You should call inject\Magento\Store\Model\StoreManagerInterface $storeManager
at
__construct( )
function at block classjust like :
Updated:
Also,you can get base url directly at
phtml
using direct call ofobject Manager
.Note:
Directly call of object manager is not good idea
. If you want base url at phtml then injectStoreManagerInterface
at block