我有一个具有这种结构的类别模型:
ID,名称PARENT_ID
我想创建一条breacrumb风格的路径,但我不知道如何。 请帮帮我。
谢谢。
答案 0 :(得分:1)
你给我们的工作很少。
以下代码用于获取下拉树。您可以根据您的面包屑示例进行调整。
/**
* Create a tree dropdown based on the parent child relationships
*
* @param $parents Array of Category models to draw list for
* @return array listitem with populated tree.
*
* @access public
*/
public function makeDropDown($parents)
{
global $listItems;
$listItems = array();
$listItems['0'] = '== Choose a Category ==';
foreach ($parents as $parent) {
$listItems[$parent->category_id] = $parent->category_name;
$this->subDropDown($parent->categories);
}
return $listItems;
}
/**
* Create a tree dropdown based of a child
*
* @param $children Array of children models to draw list for
* @param $space String identation string
* @return array listitem with populated tree.
*
* @access private
*/
private function subDropDown($children, $space = '---')
{
global $listItems;
foreach ($children as $child) {
$listItems[$child->category_id] = $space . $child->category_name;
$this->subDropDown($child->categories, $space . '---');
}
}