Home Backend Development PHP Tutorial About the implementation of infinite classification and recursion in CI framework

About the implementation of infinite classification and recursion in CI framework

Jun 14, 2018 pm 02:04 PM
ci recursion

CodeIgniter is a lightweight but powerful PHP framework. Based on the MVC design pattern, it provides a rich set of class libraries that are easy to learn, efficient and practical. The following is an introduction to the implementation code of infinite classification recursion of the CI framework. Interested friends can refer to it

What is CI?

CodeIgniter is a lightweight but The powerful PHP framework, based on the MVC design pattern, provides a rich set of class libraries that are easy to learn, efficient and practical.

Let’s take a look at the implementation code of CI framework infinite classification recursion. The specific code is as follows:

//无级分类+递归
public function digui(){
$crr = $this->db->get('category')->result_array();
$list['type'] = $this->nolimit($crr,0,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;
}
<td><?PHP echo str_repeat('    ',$val['level'])?><?php echo $val['cat_name']?></td>
//获取1级、2级、3级分类
public function sel_child($p_id){
$arr = $this->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);
}
<?php foreach($type as $v){?>
<li id="cat_1" class="">
<h3><a href=""><?php echo $v['cat_name']?></a></h3>
<?php foreach($v['child'] as $vv){?>
<dl class="clearfix">
<dt><a href=""><?php echo $vv['cat_name']?></a></dt>
<?php foreach($vv['childs'] as $vvv){?>
<a href=""><?php echo $vvv['cat_name']?></a>
<?php }?>
</dl>
<?php }?>
</li>
<?php }?>
Copy after login

The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use the CodeIgniter framework to implement image uploading

About the CodeIgniter framework verification code class library file Analysis of usage

The above is the detailed content of About the implementation of infinite classification and recursion in CI framework. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Recursive implementation of C++ functions: Is there a limit to recursion depth? Recursive implementation of C++ functions: Is there a limit to recursion depth? Apr 23, 2024 am 09:30 AM

Recursive implementation of C++ functions: Is there a limit to recursion depth?

Do C++ lambda expressions support recursion? Do C++ lambda expressions support recursion? Apr 17, 2024 pm 09:06 PM

Do C++ lambda expressions support recursion?

Recursive program to find minimum and maximum elements of array in C++ Recursive program to find minimum and maximum elements of array in C++ Aug 31, 2023 pm 07:37 PM

Recursive program to find minimum and maximum elements of array in C++

Count the number of occurrences of a substring recursively in Java Count the number of occurrences of a substring recursively in Java Sep 17, 2023 pm 07:49 PM

Count the number of occurrences of a substring recursively in Java

Recursive implementation of C++ functions: Comparative analysis of recursive and non-recursive algorithms? Recursive implementation of C++ functions: Comparative analysis of recursive and non-recursive algorithms? Apr 22, 2024 pm 03:18 PM

Recursive implementation of C++ functions: Comparative analysis of recursive and non-recursive algorithms?

Detailed explanation of C++ function recursion: application of recursion in string processing Detailed explanation of C++ function recursion: application of recursion in string processing Apr 30, 2024 am 10:30 AM

Detailed explanation of C++ function recursion: application of recursion in string processing

A beginner's guide to C++ recursion: Building foundations and developing intuition A beginner's guide to C++ recursion: Building foundations and developing intuition May 01, 2024 pm 05:36 PM

A beginner's guide to C++ recursion: Building foundations and developing intuition

How to use Vue form processing to implement recursive nesting of forms How to use Vue form processing to implement recursive nesting of forms Aug 11, 2023 pm 04:57 PM

How to use Vue form processing to implement recursive nesting of forms

See all articles