码迷,mamicode.com
首页 > 其他好文 > 详细

权限中的递归遍历,导航栏的交替,该用户的权限

时间:2018-10-14 20:40:54      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:ble   lis   mil   microsoft   foreach   space   lang   static   func   

HTML页面:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
li{
list-style: none;
}
</style>
</head>
<body>
<div>
<ul>
{volist name="res" id="v"}
<li class="yi">{$v.power_name}</li>
<div>
<ul>
{volist name="v.son" id="vv"}
<li><a href=‘{:url("$vv[controller_name]"."/"."$vv[action_name]")}‘>{$vv.power_name}</a></li>
{/volist}
</ul>
</div>
{/volist}
</ul>
</div>
<script src="__STATIC__/js/jquery.min.js"></script>
<script>
$(document).on("click",".yi",function () {
$(this).next("div").slideToggle()
})
</script>
</body>
</html>
PHP页面:
<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Welcome extends Controller
{
//主页面
public function index()
{
$user=Session::get("user",‘think‘);
$u_id=$user[‘u_id‘];
$data=Db::query("select * from power where power_id in(select powerid from role_power where role_id in(select role_id from user_role where user_id=‘$u_id‘))");
Session::set("data",$data,‘think‘);
$res=$this->digui($data,$p_id=0);
return view("show",[‘res‘=>$res]);
}
//递归
public function digui($data,$p_id=0)
{
$child=[];
foreach ($data as $k=>$v)
{
if($v[‘p_id‘]==$p_id)
{
$child[]=$v;
}
}
//二级
foreach ($child as $kk=>$vv)
{
$res=$this->digui($data,$vv[‘power_id‘]);
$child[$kk][‘son‘]=$res;
}
//返回值
return $child;
}
}
 

权限中的递归遍历,导航栏的交替,该用户的权限

标签:ble   lis   mil   microsoft   foreach   space   lang   static   func   

原文地址:https://www.cnblogs.com/stj123/p/9787401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!