You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
namespace app\index\controller;
|
|
|
|
use think\Controller;
|
|
|
|
use think\Request;
|
|
|
|
use think\Db;
|
|
|
|
class Base extends Controller
|
|
|
|
{
|
|
|
|
function _initialize()
|
|
|
|
{
|
|
|
|
if(!session('id') || !session('name')){
|
|
|
|
header("location:".SITE_URL."/index.php/index/login");exit;
|
|
|
|
}
|
|
|
|
$data=Db::query("select * from sys_menu order by id ");
|
|
|
|
$menu= $this->getTree($data, 0);
|
|
|
|
$this->assign('topmenus',$menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTree($data, $ppd)
|
|
|
|
{
|
|
|
|
$html = '';
|
|
|
|
$ppid=-1;
|
|
|
|
foreach($data as $k => $v)
|
|
|
|
{
|
|
|
|
if($v['pid'] == $ppd)
|
|
|
|
{ //父亲找到儿子
|
|
|
|
|
|
|
|
if($v['linkurl']!=null && $v['linkurl']!="")
|
|
|
|
{
|
|
|
|
$html .= "<li ><a href=\"".url($v['linkurl'])."\" >" . $v['pidname']."</a>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$html .= "<li ><a href=\"#\" >" . $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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|