多级菜单表单显示

最近在做一个后台管理其他用户的权限管理,主要对其他管理员对每个页面的操作权限

由于需要涉及到3级功能权限(如一级是大菜单,二级是子菜单,三级是当前所有菜单的所有的操作动作)

 

代码中,构造创建三维数组,然后实现 菜单栏的效果呈现。如果三级菜单为空自动补齐(注:一二级菜单必须存在)

同时,下标里面的key是数值,将直接存储到MYSQL,这样其他管理员登陆,需要读取的就直接是数字校验是否有权限访问、操作某个function,当然了,function就是对应的执行方法,对function最好的监控,就是直接判断function方法是否存在获取其他的动作,具体的可自行研究。来张图:

 

代码直接来:

<?php

/****
* @author 陈奎宗 <kuizong_chen@139.com>
* 主要生成三级权限控制菜单
*/
class QingXinZuiLevelMenu{

private $menu = array();

function __construct(){
$this->menu = array(
//主级菜单按菜单位数+3个0+功能项目
1000=>array(
‘title’=>’产品相关’,
‘function’=>”, //public方法名
‘menu’=>array(
1001=>array(
‘title’=>’产品管理’,
‘function’=>”,
‘menu’=>array(
1002=>array(
‘title’=>’添加’,
‘function’=>”
),
1003=>array(
‘title’=>’修改’,
‘function’=>”
),
1004=>array(
‘title’=>’删除’,
‘function’=>”
),
),
),
1005=>array(
‘title’=>’分类管理’,
‘function’=>”,
‘menu’=>array(
1006=>array(
‘title’=>’添加’,
‘function’=>”
),
1007=>array(
‘title’=>’修改’,
‘function’=>”
),
1008=>array(
‘title’=>’删除’,
‘function’=>”
),
1009=>array(
‘title’=>’分类幻灯片’,
‘function’=>”
),
),
),
),
),

2000=>array(
‘title’=>’订单管理’,
‘function’=>”, //public方法名
‘menu’=>array(
2001=>array(
‘title’=>’未付款’,
‘function’=>”,
‘menu’=>array(
2002=>array(
‘title’=>’查看’,
‘function’=>”
),
2003=>array(
‘title’=>’删除’,
‘function’=>”
),
),
),
2004=>array(
‘title’=>’已付款’,
‘function’=>”,
‘menu’=>array(
2005=>array(
‘title’=>’查看’,
‘function’=>”
),
2006=>array(
‘title’=>’发货’,
‘function’=>”
),
),
),
2007=>array(
‘title’=>’已收货’,
‘function’=>”,
‘menu’=>array(
2008=>array(
‘title’=>’查看’,
‘function’=>”
),
),
),
2009=>array(
‘title’=>’已完成’,
‘function’=>”,
‘menu’=>array(
2010=>array(
‘title’=>’查看’,
‘function’=>”
),
),
),
2011=>array(
‘title’=>’退货申请’,
‘function’=>”,
‘menu’=>array(
2012=>array(
‘title’=>’查看’,
‘function’=>”
),
2013=>array(
‘title’=>’已审核’,
‘function’=>”
),
2014=>array(
‘title’=>’未审核’,
‘function’=>”
),
),
),
),
),

3000=>array(
‘title’=>’系统设置’,
‘function’=>”, //public方法名
‘menu’=>array(
3001=>array(
‘title’=>’系统设置’,
‘function’=>”,
),
),
),

);
}

//考虑页面视图的渲染关系,执行三级菜单的循环
function MaxAdminMenuKeyValue(){
$menu = $this->menu;
$html = array();
$_next = 0;
if(is_array($menu)){
foreach ($menu as $k1 => $v1){
$row = count($v1[‘menu’]);
$html[$_next] = array(
‘row’=>$row,
‘title1’=>$v1[‘title’],
‘value1’=>$k1,
);

if(isset($v1[‘menu’]) && is_array($v1[‘menu’])){
$t_default = true;
foreach ($v1[‘menu’] as $k2 => $v2){
if($t_default==true){
$html[$_next][‘title2’] = $v2[‘title’];
$html[$_next][‘value2’] = $k2;
} else {
$html[$_next][‘title2’] = $v2[‘title’];
$html[$_next][‘value2’] = $k2;
}

if(isset($v2[‘menu’]) && is_array($v2[‘menu’])){
$html[$_next][‘title3’] = array();
$html[$_next][‘value3’] = array();
$k=0;
foreach ($v2[‘menu’] as $k3 => $v3){
$html[$_next][‘title3’][$k] = $v3[‘title’];
$html[$_next][‘value3’][$k] = $k3;
$k++;
}
}
//row two ++
$t_default = false;
$_next ++;
}
}

}
}
return $this->getShellMenu($html);
}

private function getShellMenu($html){
$t = ‘<tbody>’;
for($i=0;$i<count($html);$i++){
$t.='<tr>’;
if(isset($html[$i][‘title1’])){
$t.='<td rowspan=”‘.$html[$i][‘row’].'”><input type=”checkbox” name=”menu[]” value=”‘.$html[$i][‘value1′].'”>’.$html[$i][‘title1′].'</td>’;
}
if(isset($html[$i][‘title2’])){
$t.='<td><input type=”checkbox” name=”menu[]” value=”‘.$html[$i][‘value2′].'”>’.$html[$i][‘title2′].'</td>’;
}
if(isset($html[$i][‘title3’]) && is_array($html[$i][‘title3′])){
$t.='<td>’;
for($k=0;$k<count($html[$i][‘title3’]);$k++){
$t.='<input type=”checkbox” name=”menu[]” value=”‘.$html[$i][‘value3′][$k].'”>’.$html[$i][‘title3′][$k].”;
}
$t.='</td>’;
} else {
$t.='<td></td>’;
}
$t.='</tr>’;
}
$t.='</tbody>’;
return $t;
}
}

$html = new QingXinZuiLevelMenu();

?>
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>多级菜单权限控制,请自行填写样式</title>
<meta name=”renderer” content=”webkit”>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0″>
<style>
table { width:100%;border:#000 1px solid;}
table tbody {width:100%;border:#000 1px solid;}
table tbody tr{border:red 1px solid;}
table tbody tr td{border:red 1px solid;}
table thead {width:100%;border:#000 1px solid;}
table thead th{border:red 1px solid;}
</style>
</head>
<body>
<table>
<thead><th>一级权限</td><th>二级权限</td><th>三级权限</td></thead>
<?php echo $html->MaxAdminMenuKeyValue()?>
</table>

</body>
</html>

 

源码下载:level

请尊重作者,转载请注明出处

发表评论

电子邮件地址不会被公开。 必填项已用*标注