function generateTree($items) { $items = Db::name('tree')->column('id,pid,name'); $tree = array(); foreach ($items as $item) { if (isset($items[$item['pid']])) { $items[$item['pid']]['son'][] = &$items[$item['id']]; } else { $tree[] = &$items[$item['id']]; } } return $tree; } $tree = generateTree(0); function getTreeData($tree) { foreach ($tree as $t) { echo "<li><span><i " . "class=\"icon-minus-sign\"></i>" .$t["name"]. "</span>\n<a href=\"info.php?id=".$t["id"]."\" target=\"_blank\">详细</a><ul>\n"; if (isset($t['son'])) { getTreeData($t['son']); } echo "</ul>\n</li>\n"; } } $list = getTreeData($tree); $this->assign('list',$list); return $this->view->fetch(); }
靜態檔案是這樣的
直接輸出到
不控制了.如果用變數
只輸出一級,後面就沒有了.
大神們教教我該怎麼寫,謝謝.