public function navlist() { $goodstype = M('goodstype'); $data = $goodstype->field("id,name,pid,path,concat(path,'-',id) as npth")->order("npth")->select(); $newdata = unLimitedForLayer($data); //dump($newdata); $this->assign('type', $newdata); $this->display('Index:navlist'); }
function unLimitedForLayer($cate, $name = 'child', $pid = 0) { $arr = array(); foreach ($cate as $v) { if ($v['pid'] == $pid) { $v[$name] = unLimitedForLayer($cate, $name, $v['id']); $arr[] = $v; } } return $arr; }