1. 程式人生 > >tp5無限級分類

tp5無限級分類

<?php
namespace Admin\Model;
use Think\Model;
class CateModel extends Model {

 protected $_validate = array(
 array('catename','require','管理員名稱不得為空!',1),
 );


 public function catetree(){
 $data=$this->order('id desc')->select();
 return $this->resort($data);
 }

 public function resort($data,$pid=0,$level=0){
 static $arr=array();
 foreach ($data as $k => $v) {
 if ($v['pid']==$pid) {
 $v['level']=$level;
 $arr[]=$v;
 $this->resort($data,$v['id'],$level+1);
 }
 }
 return $arr;
 }

}