Preparations for RBAC 1 in thinkphp tutorial

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. Many people do not understand how to use RBAC. In fact, it is not difficult to understand it. Just take a look at the RBAC class.
We analyze the RBAC class to understand how this permission is implemented.
First, let's briefly understand RBAC. as its name implies, RBAC is a role-based permission design. Since permissions are assigned based on the role, we have to have the role table, permission table, and permission table corresponding to the role, which is the most basic. What is a role, that is, your identity, your position, that is, a user's identity can gain some power. To put it bluntly, a role is governed by a user. A Role group can have multiple users. A single user may also have multiple roles with many-to-many relationships.
Open RBAC. class. php and you will find that the official website has told you what you need to prepare. First, the configuration file needs to be set as follows: // Add settings to the configuration file
// Authenticate USER_AUTH_ON
// USER_AUTH_TYPE Authentication Type 1 logon authentication 2 Real-Time Authentication
// USER_AUTH_KEY ID
// REQUIRE_AUTH_MODULE requires authentication module
// The NOT_AUTH_MODULE does not require authentication.
// USER_AUTH_GATEWAY authenticates the Gateway
// RBAC_DB_DSN database connection DSN
// RBAC_ROLE_TABLE role table name
// RBAC_USER_TABLE User table name
// RBAC_ACCESS_TABLE permission table name
// RBAC_NODE_TABLE node table name
The data tables to be prepared: /*
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `think_access` (
`role_id` smallint(6) unsigned NOT NULL,
`node_id` smallint(6) unsigned NOT NULL,
`level` tinyint(1) NOT NULL,
`module` varchar(50) DEFAULT NULL,
KEY `groupId` (`role_id`),
KEY `nodeId` (`node_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `think_node` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`title` varchar(50) DEFAULT NULL,
`status` tinyint(1) DEFAULT '0',
`remark` varchar(255) DEFAULT NULL,
`sort` smallint(6) unsigned DEFAULT NULL,
`pid` smallint(6) unsigned NOT NULL,
`level` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `level` (`level`),
KEY `pid` (`pid`),
KEY `status` (`status`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `think_role` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`pid` smallint(6) DEFAULT NULL,
`status` tinyint(1) unsigned DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `pid` (`pid`),
KEY `status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

CREATE TABLE IF NOT EXISTS `think_role_user` (
`role_id` mediumint(9) unsigned DEFAULT NULL,
`user_id` char(32) DEFAULT NULL,
KEY `group_id` (`role_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
*/
Of course, you have to have your user table such as think_user. Well, this is the most basic preparation work.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.