public function _initialize() { if (ismobile()) { C('DEFAULT_THEME', 'mobile'); } //全局首页,用户个人中心导航分类展示 $cats = M('Category')->where('isverify=1')->order('sort asc')->select(); $cats = list2layer($cats, 0); // dump($cats); $this->assign('cats', $cats); }
function list2layer($cats, $pid) { $arr = array(); $pid = intval($pid, 10); foreach ($cats as $cat) { $id = intval($cat['pid'], 10); if ($id == $pid) { $cat['children'] = list2layer($cats, $cat['id']); $arr[] = $cat; } } return $arr; }