如何获得Magento 2安全基本URL?

时间:2018-01-10 04:50:58

标签: magento magento2

我正在使用下面的代码在magento 2中获取基本网址。

$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
echo $baseurl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); 

让我知道如何获得安全的基本网址。

3 个答案:

答案 0 :(得分:2)

你的代码是正确的,只需用true方法传递第二个参数boolean getBaseUrl(),默认为null,使用下面的代码如下:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
echo $baseurl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); 
echo $secureBaseUrl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB,true); 

答案 1 :(得分:0)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
echo $secureBaseUrl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB,true);

答案 2 :(得分:0)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

echo $find_base_url=$storeManager->getStore()->getBaseUrl();