CREATE TABLE `t_menuinfomation` (
`MI_ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '菜单信息表ID',
`MI_MenuName` varchar(100) NOT NULL COMMENT '菜单信息表菜单名称',
`MI_URL` varchar(100) DEFAULT NULL COMMENT '菜单信息表菜单URL',
`MI_ParentNode` varchar(45) DEFAULT NULL COMMENT '菜单信息表父节点',
`MI_GroupName` varchar(100) NOT NULL COMMENT '菜单信息表分组名称',
`MI_StateID` int(10) unsigned NOT NULL COMMENT '菜单信息状态ID',
`MI_IClass` varchar(500) DEFAULT NULL,
PRIMARY KEY (`MI_ID`),
UNIQUE KEY `MI_ID_UNIQUE` (`MI_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; 存储过程:delimiter $$
drop procedure if exists proc_GetMenuInformationByParameter $$
create procedure proc_GetMenuInformationByParameter
(
_MI_ID int,
_MI_GroupName varchar(10),
_MI_StateID int
)
begin
set @orderHead='select MI_ID,MI_MenuName,MI_URL,MI_ParentNode,MI_GroupName,mi_StateID, bi_Content as mi_StateStr,MI_IClass from t_menuinfomation inner join t_basicinformation on mi_stateid=bi_ID '; -- 执行命令列
set @orderParameter=' where 1=1 ';
if _MI_ID<>0 then
set @orderParameter=CONCAT(@orderParameter,CONCAT(' AND MI_ID=',_MI_ID));
end if;
if trim(_MI_GroupName)<>'' then
set @orderParameter=CONCAT(@orderParameter,CONCAT(' AND MI_GroupName=''',_MI_GroupName,''''));
end if;
if trim(_MI_StateID)<>0 then
set @orderParameter=CONCAT(@orderParameter,CONCAT(' AND MI_StateID=',_MI_StateID));
end if;
set @orderSql=CONCAT(@orderHead,@orderParameter);
prepare stmt from @orderSql; -- 预编译 !!!!
EXECUTE stmt;
end$$
delimiter ;信息列表:public function getMenuList($saID='')
{
//echo "this is getMenuList Controller show in menu page";
$menuEvent= A('GetData','Event'); //A('GetData','Event');
$MenuList=$menuEvent->getMenuInfor('');
//dump($MenuList);
$MenuList=$menuEvent->initMenuTree($MenuList,0);
//dump($MenuList[0]);
//dump($MenuList);
$this->assign('menuList',$MenuList);
$this->display("Test:menu");
}Event code:public function getMenuInfor($value='')
{
# code...
#
//echo "this is getData Event";
$menu=D();
$sql='call proc_GetMenuInformationByParameter (0,"","")';
$menuInfoList=$menu->query($sql);
//$menu->Show();
$children = array('children' =>array() );
for ($i=0; $i <count($menuInfoList); $i++) {
# code...
$menuInfoList[$i]=array_merge_recursive($menuInfoList[$i], $children );
}
return ($menuInfoList);
}
//处理返回结果集
public function initMenuTree($menuInfo,$pid)
{
$tree='';
foreach ($menuInfo as $k => $v) {
if($v['MI_ParentNode'] == $pid)
{ //父亲找到儿子
$v['children'] = $this->initMenuTree($menuInfo, $v['MI_ID']);
$tree[] = $v;
//unset($data[$k]);
}
}
return $tree;
}页面部分利用volist标签加入部分小脚本实现了效果。ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。