您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 喀什分类信息网,免费分类信息发布

ThinkPHP自动填充实现无限级分类的方法_php实例

2024/5/13 21:10:06发布56次查看
本文实例展示了thinkphp自动填充实现无限级分类的方法,是thinkphp常用功能之一,非常具有实用价值。现将完整实例分享给大家,供大家参考。具体实现步骤如下:
表aoli_cate如下图所示:
一、action部分:
aoli/home/lib/action/cataaction.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('添加栏目失败'); } //dump($vo); }else{ $this->error($cate->geterror()); } } }?>
二、模型部分:
aoli/home/lib/model/catamodel.class.php文件如下:
where(id=$pid)->find(); $data=$list['path'].'-'.$list['id'];//子类的path为父类的path加上父类的id } return $data; }}?>
三、view视图部分
aoli/home/tpl/default/cate/index.html页面如下:
请选择父级栏目: 根栏目 for($i=0;$i<$vo['count'];$i++){ echo ' '; } {$vo['name']}
新的栏目名称:

相信本文所述实例对大家thinkphp程序设计有一定的参考价值。
喀什分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录