【问题标题】:How to get Magento 2 secure base URL?如何获取 Magento 2 安全的基本 URL?
【发布时间】:2018-01-10 04:50:58
【问题描述】:

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

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

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

【问题讨论】:

    标签: magento magento2


    【解决方案1】:

    您的代码是正确的,只需将第二个参数 boolean truegetBaseUrl() 方法传递,默认为 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); 
    

    【讨论】:

      【解决方案2】:
      $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);
      

      【讨论】:

        猜你喜欢
        • 2014-11-06
        • 1970-01-01
        • 2011-11-22
        • 2015-03-07
        • 1970-01-01
        • 2012-11-22
        • 1970-01-01
        • 1970-01-01
        • 2021-12-28
        相关资源
        最近更新 更多