Magento:对非对象调用成员函数count()
在Magento中添加子类别时,出现以下错误:Magento:对非对象调用成员函数count(),magento,Magento,在Magento中添加子类别时,出现以下错误: Fatal error: Call to a member function count() on a non-object in C:\wamp\www\cariocawear_new\app\code\local\Mage\Catalog\Block\Navigation.php on line 324 这是第324行的功能: public function drawImgItem($category, $level = 0, $last =
Fatal error: Call to a member function count() on a non-object in C:\wamp\www\cariocawear_new\app\code\local\Mage\Catalog\Block\Navigation.php on line 324
这是第324行的功能:
public function drawImgItem($category, $level = 0, $last = false)
{
$html = '';
$categoryName = '';
if (!$category->getIsActive()) {
return $html;
}
$children = $category->getChildren();
$hasChildren = $children && $children->count(); <-- This is line 324 which cause error
$html.= '<li';
if ($hasChildren) {
$html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
}
/* snipped by editor for being superfluous */
}
公共函数drawImgItem($category,$level=0,$last=false)
{
$html='';
$categoryName='';
如果(!$category->getIsActive()){
返回$html;
}
$children=$category->getChildren();
$haschilds=$children&&$children->count();这似乎是该代码中的错误,因为函数$category->getChildren()通常返回字符串而不是对象
我认为在为以下内容替换第323行的代码时,您应该能够使其正常工作,但是我还没有测试它!
$children = $category->getCollection()
->addFieldToFilter('entity_id', array('in',
explode(',', $category->getChildren())));
现在获取此错误处理您的请求SQLSTATE[42S22]时出错:未找到列:1054未知列“category_id”在“where子句”中我检查了,您是对的,它应该是“entity_id”;我修改了代码段。