This article brings the content is about the TP5 framework under the recursive implementation of infinite Classification (code example), there is a certain reference value, the need for friends can refer to, I hope to help you.
I use the TP5 framework, because the project with unlimited classification, so I create a extend inside a catetree package and then create a class catetee.php, you can directly reference in the controller can be
<?phpnamespace catetree;class catetree {public Function Catetree ($cateRes) {return $this->sort ($cateR ES); The Public function sort ($cateRes, $pid =0, $level =0) {static $arr =array (); foreach ($cateRes as $k = + $v) {if ($v [' pid ']== $pid) {$v [' level ']= $level; $arr []= $v; $this->sort ($cateRes, $v [' id '], $level + 1); }} return $arr; }//Get sub-column ID public function childrenids ($cateid, $obj) {$data = $obj->field (' Id,pid ')->select (); return $this->_childrenids ($data, $cateid, TRUE); } Private Function _childrenids ($data, $cateid, $clear =false) {static $arr =array (); if ($clear) {$arr =array (); } foreach ($data as $k = + $v) {if ($v [' pid ']== $cateid) {$arr []= $v [' id ']; $this->_childrenids ($data, $v [' id ']); }} return $arr; }//Processing column sort public functioN Catesort ($data, $obj) {foreach ($data as $k + $v) {$obj->update ([' id ' = + $k, ' sort ' = ' + $v]); }}//Process bulk Delete public function Pdel ($cateids) {foreach ($cateids as $k = = $v) {$children idsarr[]= $this->childrenids ($v); $childrenidsarr []= (int) $v; } $_childrenidsarr=array (); foreach ($childrenidsarr as $k = + $v) {if (Is_array ($v)) {foreach ($v as $k 1 + = $v 1) {$_childrenidsarr[]= $v 1; }}else{$_childrenidsarr[]= $v; }} $_childrenidsarr=array_unique ($_childrenidsarr); $this::d Estroy ($_childrenidsarr); }}