我正在尝试让所有的网站在自定义模板中使用。我在我的代码块中创建了以下代码;
public function getWebsites()
{
return $this->_storeManager->getWebsites();
}然后我尝试在我的模板中使用这个来迭代网站;
<?php foreach ($block->getWebsites() as $website): ?>当页面试图加载时,我会得到;
警告:为foreach()提供的参数无效
我已经尝试了所有可能的变体,但似乎都不能让它工作。它在许多论坛上被多次引用,被认为是检索所有网站的正确方法,但它对我来说就是行不通。
如何在我的模板中获得一个网站数组?
发布于 2017-07-01 05:41:39
protected $_storeRepository;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreRepository $StoreRepository
) {
parent::__construct($context);
$this->_storeRepository = $StoreRepository;
}
public function getWebsite()
{
$stores = $this->_storeRepository->getList();
$websiteIds = array();
foreach ($stores as $store) {
$websiteId = $store["website_id"];
array_push($websiteIds, $websiteId);
}
return $websiteIds;
}https://stackoverflow.com/questions/37926348
复制相似问题