Magento 致命错误:对第44行list.phtml中的非对象调用成员函数getLevel()

Magento 致命错误:对第44行list.phtml中的非对象调用成员函数getLevel(),magento,Magento,致命错误:对第44行list.phtml中的非对象调用成员函数getLevel 在搜索时获取错误 <?php $_productCollection=$this->getLoadedProductCollection(); $_helper = $this->helper('catalog/output'); $_collectionSize = $_productCollection->count(); ?> <?php $currentCat =

致命错误:对第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())
?>

她是我的代码,这是如何做到无错误的

很可能是您在使用此list.phtml,而不是在类别列表页面上

您最好先进行检查以确保所检索的值的格式正确

$currentCat = Mage::registry('current_category');
if (get_class($currentCat) == "Mage_Catalog_Model_Category"){
    if ($currentCat->getLevel() !=2 ){

这样可以确保在尝试对其调用方法之前拥有一个Category对象。

能否包含list.phtml的所有代码?目前,第44行有一个错误,但这里只有41行代码。