PHP无限极菜单
权限表结构
CREATE TABLE `blog_auth` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '序号',
`pid` int(11) NOT NULL COMMENT '父级ID',
`auth_name` varchar(191) NOT NULL COMMENT '权限名字',
`auth_title` varchar(191) NOT NULL COMMENT '权限标题',
`auth_icon` varchar(191) DEFAULT NULL COMMENT '权限图标',
`auth_rule` varchar(191) NOT NULL COMMENT '权限路径',
`menu` tinyint(1) NOT NULL COMMENT '菜单 1=>显示菜单,0=>不显示菜单',
`debug` tinyint(1) NOT NULL COMMENT '调试模式 1-->仅调试模式显示,0-->任何时候都显示',
`create_by` int(11) NOT NULL COMMENT '创建人',
`update_by` int(11) NOT NULL COMMENT '更新人',
`create_time` int(11) NOT NULL COMMENT '创建时间',
`update_time` int(11) NOT NULL COMMENT '更新时间',
`delete_time` int(11) NOT NULL COMMENT '删除时间',
`sort` int(11) NOT NULL COMMENT '排序字段',
`status` tinyint(1) NOT NULL COMMENT '状态',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
相关代码
/**
* @title 菜单列表
* @param int $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getMenuList($uid = 0)
{//展示只有菜单类型的权限列表
$auth_list_info = Db::name('auth')->field(['id','pid','auth_title','auth_rule'])->select();
if ($auth_list_info === null){return [];}
$auth_list_info = is_array($auth_list_info) ? $auth_list_info : $auth_list_info->toArray();
return $this->getSonsInfo($auth_list_info);
} /**
* @title 菜单树生成
* @param array $items - 数据
* @param int $pid - 父级ID的值
* @param int $deep - 深度
* @return array
*/
protected function getSonsInfo(array $items,$pid=0,$deep=0)
{
$lists = [];
foreach ($items as $item){
if ($item['pid'] === $pid){
$item['deep'] = $deep;
$item['son'] = $this->getSonsInfo($items,$item['id'],$deep+1);
$lists[] = $item;
}
}
return $lists;
}
打印结果
Array ( [0] => Array ( [id] => 1 [pid] => 0 [auth_title] => 博客后台人员账户 [auth_rule] => backend/account/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 2 [pid] => 1 [auth_title] => 博客后台人员账户列表页 [auth_rule] => backend/account/index [deep] => 1 [son] => Array ( ) ) ) ) [1] => Array ( [id] => 9 [pid] => 0 [auth_title] => 博客后台首页 [auth_rule] => backend/index/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 10 [pid] => 9 [auth_title] => 博客后台首页 [auth_rule] => backend/index/index [deep] => 1 [son] => Array ( ) ) ) ) [2] => Array ( [id] => 19 [pid] => 0 [auth_title] => 博客后台文章管理 [auth_rule] => backend/article/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 20 [pid] => 19 [auth_title] => 博客后台文章列表页 [auth_rule] => backend/article/index [deep] => 1 [son] => Array ( ) ) ) ) )
PHP无限极菜单的更多相关文章
- bootstrap 无限极菜单
<ul class='wraplist' > <li class="open"> <a hr ...
- JavaScript无限极菜单
<!DOCTYPE html> <html> <head> <title> New Document </title> <meta c ...
- layui动态无限极菜单
ajax加jQuery实现 效果图 参考文章:https://www.wanpishe.top/detail?blogId=644aa177-9795-456a-8090-ee1264bf5d9d
- PHP实现菜单无限极分类
菜单数据 这里我们的菜单数据是临时数据, 没有从数据库中查询处理,数据基本和数据库中的的相似. 数据如下: $items = array( 1 => array('id' => 1, 'p ...
- C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现之方法二:加入缓存机制
在上一篇文章中我用递归方法实现了管理菜单,在上一节我也提到要考虑用缓存,也算是学习一下.Net Core的缓存机制. 关于.Net Core的缓存,官方有三种实现: 1.In Memory Cachi ...
- C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现
今天做一个管理后台菜单,想着要用无限极分类,记得园子里还是什么地方见过这种写法,可今天找了半天也没找到,没办法静下心来自己写了: 首先创建节点类(我给它取名:AdminUserTree): /// & ...
- asp.net sql无限极分类实例程序
数据库结构 代码如下 复制代码 create table category( id int, clsno ...
- 基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)
先从后台讲起 1.表的设计 parent_id就是另外一条记录的id,无限极表设计可以参考 http://m.blog.csdn.net/Rookie_Or_Veteran/article/deta ...
- sqlalchemy tree 树形分类 无限极分类的管理。预排序树,左右值树。sqlalchemy-mptt
简介: 无限极分类是一种比较常见的数据格式,生成组织结构,生成商品分类信息,权限管理当中的细节权限设置,都离不开无限极分类的管理. 常见的有链表式,即有一个Pid指向上级的ID,以此来设置结构.写的时 ...
随机推荐
- 3-自定义构造方法和description方法
http://www.cnblogs.com/mjios/archive/2013/04/19/3031412.html -自定义构造方法和description方法 1 默认的构造方法是什么?有什么 ...
- Java core dump
目录 生成Java core dump core dump分析 生成Java core dump 可以按照下面这个文章的指引来通过jni调用触发Java core dump Generating a ...
- Flutter移动电商实战 --(36)FlutterToast插件使用
https://github.com/PonnamKarthik/FlutterToast fluttertoast: ^3.0.1 category_page.dart页面添加引用 import ' ...
- linux内核中rtc框架选用什么接口来注册rtc设备呢?
1. 有哪些接口? 1.1 devm_rtc_device_register 1.2 devm_rtc_allocate_device和 rtc_register_device 2. 1.1与1.2 ...
- CImage中m_hBitmap!=0弹框报错
见图.查资料说是图片打印出现问题. 我的代码流程主要是:读图到CImage中,然后转移到数组中,将原对象销毁,对图像内容处理后,保存. 原来没问题,在加了参数循环后报错. 考虑到是循环中一些因素初始化 ...
- vue2.0+vue-video-player实现hls播放的案例
1. 安装依赖. npm install vue-video-player --save 2. 在main.js引入vue-video-player. import VueVideoPlayer fr ...
- <c:if test="${uns ne ‘admin’}">
类别 运算符 算术运算符 + . - . * . / (或 div )和 % (或 mod ) 关系运算符 == (或 eq ). != (或 ne ). < (或 lt ). > (或 ...
- PowerDesigner设置code和name不联动的方法
按照如下设置即可: 具体步骤:菜单:Tools--General Options--Name to Code mirroring的复选框不要选中.
- leetcode 区间合并
个区间若能合并,则第一个区间的右端点一定不小于第二个区间的左端点.所以先把区间集合按照左端点从小到大进行排序,接着从第一个区间开始遍历,对每个区间执行如下操作: 1.首先保存该区间的左端点start和 ...
- 神经网络手写数字识别numpy实现
本文摘自Michael Nielsen的Neural Network and Deep Learning,该书的github网址为:https://github.com/mnielsen/neural ...