Yotaku's development diary (1)
2015-12-1821:17:46 I have been looking at the Thinkphp framework for several days and now I see role-based user access control. The relevant code is as follows: Database User Table (Administrator) mg_id mg_name mg_pwd mg_time mg_role_id 0 creatint 123 2587413547 1 1 yotaku 123 258744984 4 CREAATE TABLE `sw_manager
2015-12-18 21:17:46
I have been looking at the Thinkphp framework for several days and now I see role-based user access control.
The relevant code is as follows:
Database
User table (administrator)
mg_id | mg_name | mg_pwd | mg_time | mg_role_id |
---|---|---|---|---|
0 | creatint | 123 | 2587413547 | 1 |
1 | yotaku | 123 | 258744984 | 4 |
CREAATE TABLE `sw_manager` ( `mg_id` int(11) NOT NULL AUTO_INCREMENT, `mg_name` varchar(32) NOT NULL, `mg_pwd` varchar(32) NOT NULL, `mg_time` int(10) unsigned NOT NULL COMMENT '时间', `mg_role_id` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '角色id', PRIMARY KEY (`mg_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Permission table
auth_id(权限ID) | auth_name(权限名称) | auth_pid(父id) | auth_c(控制器) | auth_a(操作方法) | auth_path(全路径) | auth_level(权限级别) |
---|---|---|---|---|---|---|
100 | 产品中心 | 0 | '' | '' | 100 | 0 |
101 | 产品展示 | 100 | ManagerController | show | 100-101 | 1 |
CREATE TABLE `sw_auth` ( `auth_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, `auth_name` varchar(20) NOT NULL COMMENT '权限名称', `auth_pid` smallint(6) unsigned NOT NULL COMMENT'父id', `auth_c` varchar(32) NOT NULL DEFAULT '' COMMENT '控制器', `auth_a` varchar(32) NOT NULL DEFAULT '' COMMENT '操作方法', `auth_path` varchar(32) NOT NULL COMMENT '全路径', `auth_level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '级别', PRIMARY KEY(`auth_id`) ) ENGING-InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Character List
role_id | role_name | role_auth_ids | role_auth_ac |
---|---|---|---|
0 | 站主 | 1,3,9 | 操作器-控制器,操作器-控制器,... |
1 | 高级管理员 | 1,2,3,9,12 | 操作器-控制器,操作器-控制器,... |
CREATE TABLE `sw_role` ( `role_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, `role_name` varchar(20) NOT NULL COMMENT '角色名称', `role_auth_ids` varchar(128) NOT NULL DEFAULT '' COMMENT '权限id,1,3,..', `role_auth_ac` text COMMENT '控制器2-操作3,控制器1-操作6,...', PRIMARY KEY(`role_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;<br><br>
数据模拟:
1.权限数据
产品中心(产品展示,最新产品,分类管理,子类管理) 高级管理(用户留言,留言簿,产品订购,文件管理) 系统管理(基本设置,样式管理,首页设置,管理员列表)
<span class="zhushi">顶级权限</span> insert into sw_auth values ( 100,'产品中心',0,'','',100,0 ); insert into sw_auth values ( 101,'高级管理',0,'','',101,0 ); insert into sw_auth values ( 102,'系统管理',0,'','',102,0 ); insert into sw_auth values ( 103,'权限管理',0,'','',103,0 ); <span class="zhushi">次级权限</span> insert into sw_auth values ( 104,'产品展示',100,'Goods','show','100-104',1 ); insert into sw_auth values ( 105,'最新产品',100,'Goods','showlist','100-105',1 ); insert into sw_auth values ( 106,'分类管理',100,'Goods','cate','100-106',1 ); insert into sw_auth values ( 107,'用户留言',101,'Goods','Words','101-107',1 ); insert into sw_auth values ( 108,'留言簿', 101,'Goods','wordsbook','101-108',1 ); insert into sw_auth values ( 109,'基本设置',102,'Goods','set','102-109',1 ); insert into sw_auth values ( 110,'样式管理',102,'Goods','CSS','102-110',1 ); insert into sw_auth values ( 111,'用户列表',103,'Goods','userlist','103-111',1 ); insert into sw_auth values ( 112,'角色管理',103,'Goods','role','103-112',1 ); insert into sw_auth values ( 113,'权限列表',103,'Goods','auth','103-113',1 );
2.角色数据
sw_role 站主 所有权限(103,104,105,106,107,108,109) 管理员 部分权限(104,105,109) 版主 部分权限(103,108)
<span class="zhushi">角色</span> insert into sw_role values (10,'站主','100,101,102,103,104,105,106,107,108,109,110,111,112,113','Goods-show,Goods-showlist,Goods-cate,Goods-words,Goods-wordsbook,Goods-set,Goods-css'); insert into sw_role values (11,'管理员','100,102,104,105,109','Goods-showlist,Goods-cate,Goods-css'); insert into sw_role values (12,'版主','100,101,103,106,108,113','Goods-show,Goods-set');
3.流程说明
Index控制器内 获取用户的角色id,进而获得角色权限 进行判断是否展现数据 Index控制器--->left方法--->left.html模板 Index控制器
//(1)根据用户id获取本身记录信息$mg_id = session('admin_id');
$manager_info = D('Manager')->find($mg_id); $role_id = $manager_info['mg_role_id'];
$role_info = D('Role')->find($role_id); $auth_ids = $role_info['role_auth_ids'];
$auth_infoA = D('Auth')->where("auth_level=0 and auth_id in($auth_ids)")->select();
$auth_infoB = D('Auth')->where("auth_level=1 and auth_id in($auth_ids)")->select();
$this->assign('auth_infoA',$auth_infoA); $this->assign('auth_infoB',$auth_infoB);
$this->assign('auth_info',$auth_info); $this->display();
4.模板 left.html
{foreach $auth_infoA as $k=>$v}background={$smarty.const.ADMIN_IMG_URL}/menu_bt.jpg >{$v.auth_id}) href="javascript:void(0);">{$v.auth_name} |
{$smarty.const.__MODULE__}/{$v2.auth_c}/{$v2.auth_a}" target=right>{$v2.auth_name} | |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

In Linux systems, you can use the following command to view the contents of the log file: tail command: The tail command is used to display the content at the end of the log file. It is a common command to view the latest log information. tail [option] [file name] Commonly used options include: -n: Specify the number of lines to be displayed, the default is 10 lines. -f: Monitor the file content in real time and automatically display the new content when the file is updated. Example: tail-n20logfile.txt#Display the last 20 lines of the logfile.txt file tail-flogfile.txt#Monitor the updated content of the logfile.txt file in real time head command: The head command is used to display the beginning of the log file

"Understanding VSCode: What is this tool used for?" 》As a programmer, whether you are a beginner or an experienced developer, you cannot do without the use of code editing tools. Among many editing tools, Visual Studio Code (VSCode for short) is very popular among developers as an open source, lightweight, and powerful code editor. So, what exactly is VSCode used for? This article will delve into the functions and uses of VSCode and provide specific code examples to help readers

PHP belongs to the backend in web development. PHP is a server-side scripting language, mainly used to process server-side logic and generate dynamic web content. Compared with front-end technology, PHP is more used for back-end operations such as interacting with databases, processing user requests, and generating page content. Next, specific code examples will be used to illustrate the application of PHP in back-end development. First, let's look at a simple PHP code example for connecting to a database and querying data:

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

Types of Linux log files and configuration methods In Linux systems, log files are very important. They record the running status of the system, user operations, and the occurrence of various events. By checking log files, system administrators can discover problems in time and handle them accordingly. This article will introduce the common types of log files in Linux systems and how to configure logging. 1. Types of log files System log: System log is a log file that records the operating status of the system, including system startup, shutdown, service startup and stop, etc.
