二级菜单的管理主要分为添加,删除,修改以及列表显示4个小模块,在一级菜单列表页面才可以添加二级菜单,因为没有一级菜单就不会有二级菜单
1.点击“添加二级菜单”进入添加页面,此处需要通过链接把一级菜单id传过去,控制器代码如下
//跳转到二级菜单添加页面
function addChildMenuUI(){
$smart=new Smarty();
$smart->left_delimiter="<{";
$smart->right_delimiter="}>";
$smart->assign("parentmenu",$_GET["id"]);
$smart->display("addChildMenu.tpl");
}
2.下面是添加二级菜单模板页面
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript">
function submitCheck(){
var menuname=$("#menuname").val();
var url=$("#url").val();
if(""==menuname){
alert("菜单名称不能为空");
return false;
}
if(""==url){
alert("url不能为空");
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加二级菜单</title>
<link rel="stylesheet" href="../../css/EditPage.css" type="text/css"></link>
</head>
<body>
<h1>添加二级菜单</h1>
<form action="../controller/TopMenuController.php" name="forms" method="post" >
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ebebeb" class="black">
<tr>
<td class="lable">二级菜单名称:</td>
<td>
<input type="text" name="menuname" id="menuname" /><span class="red_star">*</span>
<input type="hidden" name="type" value="createChildMenu"/>
<input type="hidden" name="parentmenu" value="<{$parentmenu}>"/>
</td>
</tr>
<tr>
<td class="lable">链接URL:</td>
<td>
<input type="text" name="url" id="url" /><span class="red_star">*</span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" onClick="javaScript:history.back(-1);" value="返回"/>
<input type="submit" value="[新增保存]" οnclick="javascrip:return submitCheck();"/>
</td>
</tr>
</table>
</form>
</body>
</html>
3.提交表单后的控制器处理代码
//添加二级菜单
function createChildMenu(){
$menuManager=new TopMenuManagerImpl();
$result=$menuManager->addMenu($_POST["menuname"], $_POST["url"], $_POST["parentmenu"]);
if("1"==$result){
listMenu();
}
}
4.addMenu的具体代码
//添加一级菜单
public function addMenu($menuName,$url,$parentMenu){
$db=new DBUtil();
$conn=$db->getConnection();
$base=new BaseDBOperate();
$sql="insert into m_menu(name,url,parentmenu) values ('$menuName','$url','$parentMenu')";
$result=$base->otherOperate($sql, $conn);
$db->close($conn);
return $result;
}
5.一级菜单列表页面的管理二级菜单功能,这个功能主要显示每个一级菜单下面对应的二级菜单,这里也要把一级菜单的id传过去,后面通过这个id来查询二级菜单
先来看看点击链接后的控制器处理代码
//管理二级菜单
function manageChildMenu(){
$menuManager=new TopMenuManagerImpl();
$result=$menuManager->childMenuManage($_GET["id"]);
$smart=new Smarty();
$smart->left_delimiter="<{";
$smart->right_delimiter="}>";
$smart->assign("childMenu",$result);
$smart->display("childMenuList.tpl");
}
接着呢就是childMenuManage
//二级菜单管理
public function childMenuManage($id){
$db=new DBUtil();
$conn=$db->getConnection();
$base=new BaseDBOperate();
$sql="select A.* from m_menu A where A.parentmenu='$id'";
$arr=$base->query($sql, $conn);
$db->close($conn);
return $arr;
}
下面是模板页面代码
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>学生管理系统</title>
<link rel="stylesheet" type="text/css" href="../../css/ListPage.css">
<script type="text/javascript" src="../../js/SubmitFun.js"></script>
<script type="text/javascript" src="../../js/jiaoyan.js"></script>
</head>
<body>
<form action="TopMenuController.php" method="POST">
<table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr class="tableHead2">
<td class=t1 align="right" width="50%">
<input type="hidden" name="type" value="deleteChildMenu" />
<input type="button" onClick="javaScript:history.back(-1);" value="返回"/>
<input type="submit" value="[删除]" id="delete" οnclick="javaScript:return recordDeletecheck()"/>
</td>
</tr>
</table>
<table style= "TABLE-LAYOUT: fixed;width:100% " border="0" cellpadding="1" cellspacing="1" class="tableMain">
<tr bgcolor="#FFFFFF" class="tableHead">
<th height="21" width="5%" align="left"><input type="checkBox" id="selectRows" οnclick="javaScript: return checkChange();"/>选择</th>
<th align="center" width="20%">名称</th>
<th align="center" width="10%">路径</th>
</tr>
<{foreach from=$childMenu item=message}>
<tr bgcolor="#FFFFFF">
<td height="21" align="left">
<input type="checkBox" name="selectIDs[]" id="news<{$message.id}>" value="<{$message.id}>" />
</td>
<td >
<div>
<a href="TopMenuController.php?type=editChildMenuUI&id=<{$message.id}>"><{$message.name}></a>
</div>
</td>
<td >
<div>
<{$message.url}>
</div>
</td>
</tr>
<{/foreach}>
</table>
</form>
</body>
</html>
这个页面也没什么特别之处,剩余的还是修改和删除的操作,这两个操作大家可以自己发挥, 一级菜单的删除也要注意删除一级菜单要一起把对应的二级菜单删除
这些代码我就不再写了,后面大家到我的资源里去下载,出于时间上的考虑用户管理和角色管理功能就不写成博客了,下次要介绍的是角色功能授权。