答案 0 :(得分:5)
准备阵列:
public function getCategoriesArray() {
$categoriesArray = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSort('path', 'asc')
->load()
->toArray();
$categories = array();
foreach ($categoriesArray as $categoryId => $category) {
if (isset($category['name']) && isset($category['level'])) {
$categories[] = array(
'label' => $category['name'],
'level' =>$category['level'],
'value' => $categoryId
);
}
}
return $categories;
}
以表格形式显示:
$fieldset->addField('categories', 'multiselect', array(
'label' => $this->__('Categories'),
'name' => 'categories',
'values' => Mage::getModel(...)->getCategoriesArray(),
));