# 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;
}
}
```