Thinkphp无限级分类代码
发布时间:2020-12-14 14:04:11 所属栏目:大数据 来源:网络整理
导读:本篇就一点一点教大家写一个无限级分类出来,其实掌握一个知识,最主要的是要掌握无限级分类的逻辑,那么写起来就很容易的多了。首先看数据库表:xp_cate 控制器:CateAction.class.php field(id,name,pid,path,concat(path,-,id)asbpath)-order(bpath)-sele
本篇就一点一点教大家写一个无限级分类出来,其实掌握一个知识,最主要的是要掌握无限级分类的逻辑,那么写起来就很容易的多了。 首先看数据库表:xp_cate 控制器:CateAction.class.phpfield("id,name,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select(); foreach($list as $key=>$value){ $list[$key]['count']=count(explode('-',$value['bpath'])); } $this->assign('alist',$list); $this->display(); }//添加栏目 function add(){ $cate=new CateModel();if($vo=$cate->create()){ if($cate->add()){ $this->success('添加栏目成功'); }else{ $this->error('添加栏目失败'); } }else{ $this->error($cate->getError()); } }} ?> 模型:CateModel.class.phpwhere("id=$pid")->find(); $data=$list['path'].'-'.$list['id'];//子类的path为父类的path加上父类的id } return $data; } } ?> 模板:index.html<form action="/Article/add" method="post"> 请选择父级栏目:<select name="pid" size="20"> <option value="0">根栏目<volist name="alist" id="vo"> <option value="{$vo['id']}"> <for start="0" end="$vo['count']"> {$vo['name']}<br/>新的栏目名称:<input type="text" name="name"/><br/><input type="submit" value="添加栏目"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |