$config = array(
// array('id'=>'1000','name'=>'个性化设置','url'=>'admin/custom/index'),
array('id' => '1001', 'name' => '菜单设置', 'url' => 'admin/menu/index'),
array('id' => '1002', 'name' => '关键词设置', 'url' => 'admin/word/index'),
array('id' => '1003', 'name' => '报告设置', 'url' => 'admin/report/index'),
array('id' => '1004', 'name' => '预警设置', 'url' => 'admin/warning/index'),
array('id' => '1005', 'name' => '角色管理', 'url' => 'admin/role/index'),
// array('id'=>'1033','name'=>'站点设置','url'=>'admin/site/index'),
array('id' => '1006', 'name' => '用户管理', 'url' => 'admin/user/index'),
array('id' => '1007', 'name' => '修改资料', 'url' => 'admin/base_info/edit'),
array('id' => '1008', 'name' => '操作日志', 'url' => 'admin/client_logs/index'),
array('id' => '1009', 'name' => '任务中心', 'url' => 'admin/schedule/index'),
array('id' => '1010', 'name' => 'OEM设置', 'url' => 'admin/custom/web', 'parent_id' => 1000),
array('id' => '1011', 'name' => '邮件Smtp设置', 'url' => 'admin/custom/smtp', 'parent_id' => 1000),
array('id' => '1012', 'name' => '预警号码设置', 'url' => 'admin/custom/warn_number', 'parent_id' => 1000),
array('id' => '1013', 'name' => '菜单列表', 'url' => 'admin/menu/menu_list', 'parent_id' => 1001),
array('id' => '1014', 'name' => '添加/修改', 'url' => 'admin/menu/menu_add', 'parent_id' => 1001),
array('id' => '1015', 'name' => '模块管理', 'url' => 'admin/menu/box_list', 'parent_id' => 1001),
array('id' => '1016', 'name' => '模块添加/修改', 'url' => 'admin/menu/box_add', 'parent_id' => 1001),
array('id' => '1017', 'name' => '关键词类别设置', 'url' => 'admin/word_category/index', 'parent_id' => 1002),
array('id' => '1018', 'name' => '主题词设置', 'url' => 'admin/word/index', 'parent_id' => 1002),
array('id' => '1019', 'name' => '标签设置', 'url' => 'admin/word/tags', 'parent_id' => 1002),
array('id' => '1020', 'name' => '词表设置', 'url' => 'admin/word/wordsets', 'parent_id' => 1002),
array('id' => '1021', 'name' => '添加词表', 'url' => 'admin/word/addwordsets', 'parent_id' => 1002),
);
$newConfig = [];
foreach( $config as $key=>$val ){
if(!array_key_exists('parent_id', $val)){
$config[$key]['parent_id'] = 0;
}
}
$newConfig = list_to_tree($config);
foreach( $newConfig as $key=>$val ){
unset($newConfig[$key]['parent_id']);
}
function list_to_tree($list, $pk='id',$pid = 'parent_id',$child = '_child',$root=0) {
// 创建Tree
$tree = array();
if(is_array($list)) {
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$parent[$child][] =& $list[$key];
}
}
}
}
return $tree;
}
兼容的无限级菜单代码 php
最新推荐文章于 2023-01-12 11:44:28 发布