thinkphp 获取当前位置导航的方法
函数方法如下:
function now_here($catid,$ext=''){
$cat = M("Category");
$here = '<a href="'.__ROOT__.'">首页</a>';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$catid")->find();
if($uplevels['asmenu'] != 0)
$here .= get_up_levels($uplevels['asmenu']);
$here .= ' -> <a href="/cat_'.$uplevels['catid'].'.html">'.$uplevels['catname']."</a>";
if($ext != '') $here .= ' -> '.$ext;
return $here;
}
function get_up_levels($id){
$cat = M("Category");
$here = '';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$id")->find();
$here .= ' -> <a href="/cat_'.$uplevels['catid'].'.html">'.$uplevels['catname']."</a>";
if($uplevels['asmenu'] != 0){
$here = $this->get_up_levels($uplevels['asmenu']).$here;
}
return $here;
}
下面是在YFMCF(THINKPHP5内核CMS中使用的方法)
//获取当前位置导航的方法
function now_here($cid,$ext=''){
$cat = Db::name("menu");
$here = '<a href="'.url('home/index/index').'">首页</a>';
$uplevels = $cat->field("id,menu_name,parentid")->where("id",$cid)->find();
if($uplevels['parentid'] != 0)
$here .= get_up_levels($uplevels['parentid']);
$here .= ' <i class="iconfont icon-jiantou1"></i> <a href="/list/'.$uplevels['catid'].'">'.$uplevels['menu_name']."</a>";
if($ext != '') $here .= ''.$ext;
return $here;
}
function get_up_levels($id){
$cat = Db::name("menu");
$here = '';
$uplevels = $cat->field("id,menu_name,parentid")->where("id",$id)->find();
$here .= ' <i class="iconfont icon-jiantou1"></i> <a href="/list/'.$uplevels['id'].'">'.$uplevels['menu_name']."</a>";
if($uplevels['parentid'] != 0){
$here = get_up_levels($uplevels['parentid']).$here;
}
return $here;
}

浙公网安备 33010602011771号