写一个全局公共函数!代码如下:
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;
}
然后在需要的页面控制器中直接调用此函数