写一个全局公共函数!代码如下:
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;
}
然后在需要的页面控制器中直接调用此函数
本文介绍如何创建一个全局公共函数用于生成页面导航链接,包括从根目录到特定分类页面的链接,以及如何通过递归调用获取上级分类链接。
994

被折叠的 条评论
为什么被折叠?



