Magento2 获取基础链接(BaseUrl):
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
$baseUrl = $store->getBaseUrl();
#或者
$baseUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
Magento2 获取安全基础链接(SecureBaseUrl):
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
$baseUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true);
Magento2 获取 Media 链接:
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
$mediaUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
Magento2 获取 Web 链接:
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
$webUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
Magento2 获取 Static 链接:
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
$staticUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC);