<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
class Topmenu extends Common
{
function getTree($data,$ppd)
{
$html = '';
$ppid=-1;
foreach($data as $k =>$v)
{
if($v['pid'] == $ppd)
{
$html .= "<li ><a  href='".$v['linkurl']."' >".$v['pidname']."</a>";
$ppid=$v['ppid'];
$html .= $this->getTree($data,$v['id']);
$html = $html ."</li>";
}
}
if($ppd==0) {
return $html ?'<ul class="nav">'.$html .'</ul>': $html;
}
else
{
return $html ?'<ul  >'.$html .'</ul>': $html;
}
}
function index()
{
$data=Db::query("select * from sys_menu ");
$menu= $this->getTree($data,0);
$this->assign('data',$menu);
return $this->fetch();
}
}
?>