0
我控制器小問題問心無愧這個詞導航腳本
[code]$data['navlist'] = $this->MCats->getCategoriesNav();[/code]
模型
[code]
function getCategoriesNav(){
$data = array();
$this->db->group_by('parentid', 'id');
$Q = $this->db->get('categories');
if($Q->num_rows >0){
foreach($Q->result() as $row){
if($row->parentid > 0){
$data[0][$row->parentid]['children'][$row->id] = $row->name;
}else{
$data[0][$row->id]['name'] = $row->name;
}
}
}
$Q->free_result();
return $data;
}
[/code]
和觀點
[code]if(count($navlist)){
echo "<ul>";
foreach($navlist as $key => $list){
foreach($list as $topkey => $toplist){
echo "<li class='cat'>";
echo anchor("welcome/cat/$topkey", $toplist);
echo "</li>\n";
if(count($toplist['children'])){
foreach($toplist['children'] as $subkey => $subname){
echo "\n<li class='subcat'>";
echo anchor("welcome/cat/$subkey", $subname);
echo "</li>";
}
}
}
}
echo "</ul>\n";
}[/code]
我不是頂部菜單越來越類別名稱,請幫助我,