不用类,三张表,几行代码搞定权限分配
用户表CREATE TABLE IF NOT EXISTS `zycms_user` (<br>
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br>
`username` varchar(50) NOT NULL,<br>
`ncname` varchar(20) NOT NULL,<br>
`password` char(32) NOT NULL,<br>
`role` smallint(6) unsigned NOT NULL COMMENT '组ID',<br>
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态 1:启用 0:禁止',<br>
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',<br>
`last_login_time` int(11) unsigned NOT NULL COMMENT '最后登录时间',<br>
`last_login_ip` varchar(15) DEFAULT NULL COMMENT '最后登录IP',<br>
`last_location` varchar(100) DEFAULT NULL COMMENT '最后登录位置',<br>
PRIMARY KEY (`id`),<br>
KEY `username` (`username`)<br>
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户表' AUTO_INCREMENT=29 ;
用户组表CREATE TABLE IF NOT EXISTS `zycms_role` (<br>
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,<br>
`rolename` varchar(20) NOT NULL COMMENT '后台组名',<br>
`roleid` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '父ID',<br>
`status` tinyint(1) unsigned DEFAULT '0' COMMENT '是否激活 1:是 0:否',<br>
`sort` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '排序权重',<br>
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',<br>
`rules` text NOT NULL,<br>
PRIMARY KEY (`id`),<br>
KEY `pid` (`roleid`),<br>
KEY `status` (`status`)<br>
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
节点表CREATE TABLE IF NOT EXISTS `zycms_menu` (<br>
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,<br>
`name` char(40) NOT NULL DEFAULT '',<br>
`pid` smallint(6) NOT NULL DEFAULT '0',<br>
`m` char(20) NOT NULL DEFAULT '',<br>
`c` char(20) NOT NULL DEFAULT '',<br>
`ac` char(20) NOT NULL,<br>
`data` char(100) NOT NULL DEFAULT '',<br>
`listorder` smallint(6) unsigned NOT NULL DEFAULT '0',<br>
`isdisplay` enum('1','0') NOT NULL DEFAULT '1',<br>
`path` text NOT NULL,<br>
`tb` varchar(20) NOT NULL,<br>
PRIMARY KEY (`id`),<br>
KEY `listorder` (`listorder`),<br>
KEY `parentid` (`pid`),<br>
KEY `module` (`m`,`c`,`ac`)<br>
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=41 ;
功能实现:$rs=M('role')->where("id='{$_SESSION['roleid']}'")->find();<br>
<br>
$rules=explode(',', $rs['rules']);<br>
$thisaction=M('menu')->where("m='".GROUP_NAME."' and c='".MODULE_NAME."' and ac='".ACTION_NAME."'")->find();<br>
<br>
if(!in_array($thisaction['id'], $rules))<br>
<br>
$this->error('你无权访问');
栏目权限分配与此类似
AD:真正免费,域名+虚机+企业邮箱=0元