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