CI是什么?
CodeIgniter是一个轻量级但功能强大的PHP框架,基于MVC设计模式,提供了一套丰富的类库,简单易学,高效实用。
下面看下CI框架无限级分类+递归的实现代码,具体代码如下所示:
db->get('category')->result_array();
$list['type'] = $this->nolimit($crr,0);
$this->load->view('list1',$list);
}
public function nolimit($crr,$p_id,$level){
static $arr = array();
foreach($crr as $v){
if($v['parent_id']==$p_id){
$v['level'] = $level;
$arr[] = $v;
$this->nolimit($crr,$v['cat_id'],$level+1);
}
}
return $arr;
}
sel_son($p_id);
foreach($arr as $k=>$v){
$tmp = $this->sel_son($v['cat_id']);
foreach($tmp as $kk=>$vv){
$tmp2 = $this->sel_son($vv['cat_id']);
$tmp[$kk]['childs'] = $tmp2;
}
$arr[$k]['child'] = $tmp;
}
return $arr;
}
//通过ID获取所有的下级分类
public function sel_son($id){
$this->db->where("parent_id=$id");
return $this->db->get(self::$cate)->result_array();
}
//渲染展示主页模板
public function lists(){
$p_id = 0;
$brr['type'] = $this->Home_model->sel_child($p_id);
$brr['list'] = $this->db->get('goods')->result_array();
$this->load->view('Home/list.html',$brr);
}
以上所述是小编给大家介绍的CI框架无限级分类+递归的实现代码。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。
原文链接:https://www.f2er.com/php/18645.html