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(); }
静态文件是这样的
直接输出到
不受控制了.如果用变量
只输出一级,后面就没有了.
大神们教教我该怎么写,谢谢.