时时商务社区
标题:
Thinkphp无限级分类代码
[打印本页]
作者:
新格网络
时间:
2018-2-14 05:41
本篇就一点一点教大家写一个无限级分类出来,其实掌握一个知识,最主要的是要掌握无限级分类的逻辑,那么写起来就很容易的多了。
首先看数据库表:xp_cate
控制器:CateAction.class.php
field("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.php
where("id=$pid")->find();
$data=$list['path'].'-'.$list['id'];//子类的path为父类的path加上父类的id
}
return $data;
}
}
?>
模板:index.html
请选择父级栏目:
根栏目
{$vo['name']}
新的栏目名称:
显示结果如下:
有没有掌握无限级分类的逻辑,上文分享的thinkphp无限级分类代码,希望对大家的学习有所帮助。
您可能感兴趣的文章:
ThinkPHP自动填充实现无限级分类的方法
ThinkPHP无限级分类原理实现留言与回复功能实例
使用ThinkPHP的自动完成实现无限级分类实例详解
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2