Home > php教程 > php手册 > body text

Infinitus menu display

WBOY
Release: 2016-10-12 09:50:12
Original
1741 people have browsed it

In development projects, the display of the backend Infinitus menu is inevitable and very common. Generally, the background menu is divided into two levels, up to three levels, but there may be multiple levels. Today I will make a record of the implementation process of the Infinitus menu.

What is done here is: Role-Based Access Control. In RBAC, permissions are associated with roles, and users obtain the permissions of these roles by becoming members of the appropriate roles. This greatly simplifies the management of permissions. In an organization, roles are created to complete various tasks, and users are assigned corresponding roles based on their responsibilities and qualifications. Users can be easily assigned from one role to another. Roles can be granted new permissions based on new requirements and system integration, and permissions can also be reclaimed from a role as needed. Character-to-character relationships can be established to encompass a wider range of objective circumstances.

First introduce the following table structure:

CREATE TABLE `sp_auth` (
`auth_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`auth_name` varchar(30) NOT NULL COMMENT 'permission name',
`action_name` varchar(30) NOT NULL COMMENT 'permission code ',
`desc` varchar(120) NOT NULL DEFAULT '' COMMENT 'Permission description',
`pid` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Superior authority ID',
`sort_id` smallint(5 ) unsigned NOT NULL DEFAULT '0' COMMENT 'Permission sorting value',
`add_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Add time',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ' Update time',
`is_delete` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Whether to delete (0 not deleted | 1 deleted)',
PRIMARY KEY (`auth_id`),
UNIQUE KEY `action_name` ( `action_name`),
KEY `pid` (`pid`),
KEY `add_time` (`add_time`),
KEY `is_delete` (`is_delete`),
KEY `controller_name` (`controller_name`(6) ),
KEY `auth_name` (`auth_name`(16)),
KEY `sort_id` (`sort_id`)
) ENGINE=MyISAM AUTO_INCREMENT=113 DEFAULT CHARSET=utf8 COMMENT='Permission Table';

Processing method:

//打印无限极树形结构菜单展示<br>    function _reSorts($data, $pid=0)<br>    {<br>        $ret = array();<br>        foreach ($data as $k => $v) {<br>            if($v['pid'] == $pid) {<br>                $v['children'] = _reSorts($data, $v['auth_id']);<br>                $ret[] = $v;<br>            }<br>        }<br>        return $ret;<br>    }<br>//打印二级菜单的方法
Copy after login
function getMenuShow($data)<br>{<br>    $ret = array();<br>    if (!is_array($data)) {<br>        return false;<br>    }<br>    foreach ($data as $key => $val) {<br>        if ($val['pid'] == 0) {<br>            //再次遍历,将第二级别的放在作为其子菜单<br>            foreach ($data as $k => $v) {<br>                if ($v['pid'] == $val['auth_id']) {<br>                    $val['children'][] = $v;<br>                }<br>            }<br>            $ret[] = $val;<br>        }<br>    }<br>    return $ret;<br>}
Copy after login

This way you can get the displayed menu data.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!