我想在自动建议字段中显示所有类别列表。所以我有一个类似查询的代码:
function res($cur_category){
$children_categories = Mage::getModel('catalog/category')->getCategories($cur_category->getId());
$children_categories->addAttributeToFilter('name', array('like' => '%a%'));
foreach($children_categories as $child){
$name = $child->getName();
$option.='<li onClick="fill(\''.addslashes($child->getName()).'\');">' .$child->getName(). "</li>";
$option.=res($child);
}
unset($children_categories);
return $option;
}
function GetTree(){
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
$categories->addAttributeToFilter('name', array('like' => '%a%'));
foreach($categories as $category)
{
$option.='<li onClick="fill(\''.addslashes($category->getName()).'\');">'.$category->getName()."</li>";
if($category->hasChildren()){
$option.= res($category);
}
}
unset($categories);
return $option;
}
echo $select = '<ul>'.GetTree().'</ul>';
但是此代码不适用于类似查询,如果没有类似查询,它可以正常工作并正确显示类别列表。我怎样才能用like写查询?