【发布时间】:2013-07-09 01:21:22
【问题描述】:
如何从类别模板 (view.phtml) 之外获取当前类别图像? 例如,如果我想从 header.phtml 或 footer.phtml 获取它。
我尝试从 view.phtml 复制代码:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
但我在重新加载页面时收到此错误: 致命错误:在非对象上调用成员函数 getImageUrl()
【问题讨论】:
标签: magento magento-1.7