权限表结构

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. PHP 之快递100接口封装

    <?php /** * Created by PhpStorm. * User: Yang * Date: 2019/8/23 * Time: 10:38 */ class Kuaidi_Que ...

  2. [题解] [HEOI2013] Segment

    题面 题解 李超线段树 为了与机房大佬 HYJ 同步伐 学习笔记请移步 yyb的博客 Code #include <algorithm> #include <iostream> ...

  3. 基于Ryu REST API的VLAN实现

    目录 0.预备知识 1.实验内容 2.编写脚本addflow.sh一步实现流表下发 3.使用api查看流表 4.实验结果 0.预备知识 ryu控制器的API文档:ryu.app.ofctl_rest ...

  4. selenium 配置 chromedriver

    参考文档: https://blog.csdn.net/yoyocat915/article/details/80580066?tdsourcetag=s_pcqq_aiomsg http://npm ...

  5. Redis | 一文轻松搞懂redis集群原理及搭建与使用

    转载:https://juejin.im/post/5ad54d76f265da23970759d3 作者:SnailClimb 这里总结一下redis集群的搭建以便日后所需同时也希望能对你有所帮助. ...

  6. LC 988. Smallest String Starting From Leaf

    Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to  ...

  7. Linux学习:使用 procrank 测量系统内存使用情况

    程序员应该了解一个基本问题:我的程序使用了多少内存?这可能是一个简单的问题,但是对于像Linux这样的虚拟内存操作系统,答案是相当复杂的,因为top和ps给出的数字不能简单相加.进程中两个最常见的内存 ...

  8. GradientDrawable

    一个具有渐变区域的Drawable,可以实现线性渐变,发散渐变和平铺渐变效果 核心节点:<gradient/>,有如下可选属性: startColor:渐变的起始颜色 centerColo ...

  9. Jetson TK下如何写汇编语言

    首先,可以根据http://www.cnblogs.com/zenny-chen/p/3816620.html来安装CUDA工具链.这个工具集里包含了CUDA编译器以及其它必要的工具.然后,我们进入/ ...

  10. 数据分析 - Power BI 链接 mysql 数据分析

    链接数据库 点击确定后选择数据库, 然后输入用户名密码, 选择级别选择指定的数据库即可 之后弹出的导航器中即可有可预览的数据 更加推荐使用 再链接数据库的时候高级查询的 sql 中进行 sql 的执行 ...