权限表结构

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无限极菜单的更多相关文章

  1. bootstrap 无限极菜单

        <ul class='wraplist' >           <li class="open">                <a hr ...

  2. JavaScript无限极菜单

    <!DOCTYPE html> <html> <head> <title> New Document </title> <meta c ...

  3. layui动态无限极菜单

    ajax加jQuery实现 效果图 参考文章:https://www.wanpishe.top/detail?blogId=644aa177-9795-456a-8090-ee1264bf5d9d

  4. PHP实现菜单无限极分类

    菜单数据 这里我们的菜单数据是临时数据, 没有从数据库中查询处理,数据基本和数据库中的的相似. 数据如下: $items = array( 1 => array('id' => 1, 'p ...

  5. C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现之方法二:加入缓存机制

    在上一篇文章中我用递归方法实现了管理菜单,在上一节我也提到要考虑用缓存,也算是学习一下.Net Core的缓存机制. 关于.Net Core的缓存,官方有三种实现: 1.In Memory Cachi ...

  6. C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现

    今天做一个管理后台菜单,想着要用无限极分类,记得园子里还是什么地方见过这种写法,可今天找了半天也没找到,没办法静下心来自己写了: 首先创建节点类(我给它取名:AdminUserTree): /// & ...

  7. asp.net sql无限极分类实例程序

    数据库结构  代码如下 复制代码 create table category(    id                  int,                    clsno         ...

  8. 基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)

    先从后台讲起 1.表的设计 parent_id就是另外一条记录的id,无限极表设计可以参考  http://m.blog.csdn.net/Rookie_Or_Veteran/article/deta ...

  9. sqlalchemy tree 树形分类 无限极分类的管理。预排序树,左右值树。sqlalchemy-mptt

    简介: 无限极分类是一种比较常见的数据格式,生成组织结构,生成商品分类信息,权限管理当中的细节权限设置,都离不开无限极分类的管理. 常见的有链表式,即有一个Pid指向上级的ID,以此来设置结构.写的时 ...

随机推荐

  1. redis之哨兵集群

    一.主从复制背景问题 Redis主从复制可将主节点数据同步给从节点,从节点此时有两个作用: 一旦主节点宕机,从节点作为主节点的备份可以随时顶上来. 扩展主节点的读能力,分担主节点读压力. 但是问题是: ...

  2. c++ 容器切片反转次序(拷贝到新容器)

    code: // rotate_copy algorithm example #include <iostream> // cout #include <algorithm> ...

  3. Wondershare Video Converter Ultimate 注册码 License

    这个软件可以直接将DVD iso转换成mp4播放,可以破解,还不错,特地记录 官网下载最新版: https://videoconverter.wondershare.com/gl/video-conv ...

  4. 问题MySQL Error (2013): Lost connection to MySQL server at waiting for initial communication packet

    错误说明: SQL Error (2013): Lost connection to MySQL server at 'waiting for initial communication packet ...

  5. 使用express-session实现登录效果

    本文为后端练兵内容,重复造轮子,重复造轮子才能有经验,才能生出花来. 本次练兵,采用的是数据库保存账户密码,后端通过查数据库的方式,实现账号和密码的校验. 如果验证成功,将登陆状态保存在session ...

  6. Docker-compose的安装和使用

    一.简介 Compose 项目 是 Docker 官方的开源项目 , 负 责实 现对 Docker 容器 集群的快速编排,其前身 是开源项目 Fig, 目前仍然兼容 Fig格式的模板文件. 使用 一个 ...

  7. WebService技术规则

    1.基于web的系统级接口规范     - 一个普通适用标准 :http+xml     - 任何网络通信的操作系统     - 自包含.自描述.模块化     - 发布.定位.通过web调用  2. ...

  8. 深入理解Flink ---- End-to-End Exactly-Once语义

    上一篇文章所述的Exactly-Once语义是针对Flink系统内部而言的. 那么Flink和外部系统(如Kafka)之间的消息传递如何做到exactly once呢? 问题所在: 如上图,当sink ...

  9. Spring Aop(六)——@DeclareParents介绍

    转发:https://www.iteye.com/blog/elim-2395410 6 @DeclareParents介绍 @DeclareParents注解也是Aspectj提供的,在使用基于As ...

  10. swift 第十四课 可视化view: @IBDesignable 、@IBInspectable

    以前应objctiew-c 写项目的时候,就知道有这两个关键字,现在用swift了.用法稍作改变,基本用法还是一致的 虽然使用这个之后,有时候会报错的非常的莫名其妙----(其实还是自己技术不够牛…… ...