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;
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM