thinkphp怎么调取当前第三级栏目
我的栏目有5级,只要第三级id
catid
这个要看你表有没有字段表示层级了,这个主要看你表结构,如果没有表示层级关系的,你只能是递归去取第三级了
可以参考一下
ThinkPHP5.1 多级控制器(分层控制器)的理解和使用_手是好汉!眼是懒汉。的博客-CSDN博客
查看源文件效果:复制代码 代码如下:首页 -> PHP学习 -> ecshop -> ecshop二次开发 -> ecshop加入百度地图,支持周边标记
复制代码 代码如下://当前位置-第一个参数 catid为当前栏目的id,第二个参数为文章的标题,调用栏目当前位置时第二个参数为空即可。
$this->assign("now_here",$this->now_here($catid,$res["title"]));
//解释一下,栏目表category中的catid为栏目id,catname为栏目名称,asmenu为栏目父级的id,当为顶级栏目时,asmenu为0 。
protected function now_here($catid,$ext=""){
$cat = M("Category");
$here = "首页";
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$catid")->find();
if($uplevels["asmenu"] != 0)
$here .= $this->get_up_levels($uplevels["asmenu"]);
$here .= " -> ".$uplevels["catname"]."";
if($ext != "") $here .= " -> ".$ext;
return $here;
}
protected function get_up_levels($id){
$cat = M("Category");
$here = "";
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$id")->find();
$here .= " -> ".$uplevels["catname"]."";
if($uplevels["asmenu"] != 0){
$here = $this->get_up_levels($uplevels["asmenu"]).$here;
}
return $here;
}