致命错误:在第44行的list.phtml中的非对象上调用成员函数getLevel() 在搜索时收到错误
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$_collectionSize = $_productCollection->count();
?>
<?php
$currentCat = Mage::registry('current_category');
if($currentCat->getLevel()!=2){
if ( $currentCat->getParentId() == Mage::app()
->getStore()->getRootCategoryId() )
{
$loadCategory = $currentCat;
}
else
{
$loadCategory = Mage::getModel('catalog/category')->
load($currentCat- >getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
echo '<ul class="subcategories">';
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<li class="subicon"><a href="'.$cat->getURL().'">'
.$cat->getName().'</a></li>';
}
}
echo '</ul>';
}else{
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
她是我的代码,这是如何没有错误的
答案 0 :(得分:0)
如果不在类别列表页面上,您可能会使用此list.phtml。
您最好进行检查,以确保您首先检索的格式是正确的格式。
$currentCat = Mage::registry('current_category');
if (get_class($currentCat) == "Mage_Catalog_Model_Category"){
if ($currentCat->getLevel() !=2 ){
这样可以确保在尝试调用方法之前有一个Category对象。