# Model
```
class Newscate extends Model
{
protected $name = 'newscate';
public function tree()
{
$product = $this->order('sort_id','asc')->select();
return $this->getTree($product);
}
//无限极递归
public function getTree($data,$parent_id=0,$level=0){
static $arr=array();
foreach($data as $key=>$value){
if($value['parent_id'] == $parent_id){
//用来作为在模版进行层级的区分
$value['level']=$level;
//把内容存进去
$arr[] = $value;
//回调进行无线递归
$this->getTree($data,$value['cateid'],$level+1);
}
}
return $arr;
}
}
```