栏目组的信息结构如上表,pid表示父节点的id
static public function toLayer($cate,$name='child',$pid=0){ $arr=array(); foreach($cate as $v){ if($v['pid']==$pid){ $v[$name]=self::toLayer($cate,$name,$v['id']); $arr[]=$v; } } return $arr; }
其中$cate为查询表得到的关联数组,得到的结果数组如下:
Array
(
[0] => Array ( [id] => 1 [name] => 常规管理 [pid] => 0 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 1 [child] => Array ( [0] => Array ( [id] => 5 [name] => 栏目管理 [pid] => 1 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 11 [child] => Array ( [0] => Array ( [id] => 8 [name] => 栏目管理 [pid] => 5 [module] => Category [action] => index [parameter] => [quick] => 0 [status] => 1 [sort] => 111 [child] => Array ( ) ) ) ) [1] => Array ( [id] => 6 [name] => 内容管理 [pid] => 1 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 12 [child] => Array ( ) ) [2] => Array ( [id] => 7 [name] => 快捷面板 [pid] => 1 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 13 [child] => Array ( ) ) ) ) [1] => Array ( [id] => 2 [name] => 模块管理 [pid] => 0 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 2 [child] => Array ( [0] => Array ( [id] => 9 [name] => 内置模块 [pid] => 2 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 21 [child] => Array ( [0] => Array ( [id] => 10 [name] => 自由块管理 [pid] => 9 [module] => Block [action] => index [parameter] => [quick] => 0 [status] => 1 [sort] => 211 [child] => Array ( ) ) [1] => Array ( [id] => 11 [name] => 广告管理 [pid] => 9 [module] => Abc [action] => index [parameter] => [quick] => 1 [status] => 1 [sort] => 212 [child] => Array ( ) ) [2] => Array ( [id] => 12 [name] => 专题管理 [pid] => 9 [module] => Special [action] => index [parameter] => [quick] => 0 [status] => 1 [sort] => 213 [child] => Array ( ) ) [3] => Array ( [id] => 13 [name] => 公告管理 [pid] => 9 [module] => Announce [action] => index [parameter] => [quick] => 1 [status] => 1 [sort] => 214 [child] => Array ( ) ) [4] => Array ( [id] => 14 [name] => 友情链接 [pid] => 9 [module] => Link [action] => index [parameter] => [quick] => 1 [status] => 1 [sort] => 215 [child] => Array ( ) ) [5] => Array ( [id] => 15 [name] => 留言本管理 [pid] => 9 [module] => Guestbook [action] => index [parameter] => [quick] => 1 [status] => 1 [sort] => 216 [child] => Array ( ) ) [6] => Array ( [id] => 16 [name] => 评论管理 [pid] => 9 [module] => Comment [action] => index [parameter] => [quick] => 1 [status] => 1 [sort] => 217 [child] => Array ( ) ) ) ) [1] => Array ( [id] => 44 [name] => 其他模块 [pid] => 2 [module] => [action] => [parameter] => [quick] => 0 [status] => 1 [sort] => 22