public function build($data,$parentid=0){//分级数组
$tree=[];
foreach ($data as $node){
if($node["parentid"]==$parentid){
$children = $this->build($data,$node['id']);
if($children){
$node["children"] = $children;
}
$tree[] = $node;
}
}
return $tree;
}
public function menuView($tree, $children=false) {//显示菜单
if ($children)
$template .= "<ul class="sub-menu">";
foreach($tree as $k=>$node) {
// 当前记录有子
if ($node['children']) {
$template .= "<li class="nav-link nav-toggle"><a class="nav-link " href="javascript:;"><span class="title">".$node['menuname']."</span></a>";
$template .= $this->menuView($node['children'], true);
$template .= "</li>";
} else {
// 当前记录没有子,加上链接
$template .= "<li class="nav-item"><a href="index.php?".$node['router'].""><span class="title">".$node['menuname'] . "</span></a></li>";
}
}
if ($children)
$template .= "</ul>";
return $template;
}