zoukankan      html  css  js  c++  java
  • 权限中的递归遍历,导航栏的交替,该用户的权限

    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 appindexcontroller;

    use thinkController;
    use thinkDb;
    use thinkSession;

    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;
    }
    }
     
    你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
  • 相关阅读:
    List of the best open source software applications
    Owin对Asp.net Web的扩展
    NSwag给api加上说明
    'workspace' in VS Code
    unable to find valid certification path to requested target
    JMeter的下载以及安装使用
    exception disappear when forgot to await an async method
    Filter execute order in asp.net web api
    记录web api的request以及response(即写log)
    asp.net web api的源码
  • 原文地址:https://www.cnblogs.com/stj123/p/9787401.html
Copyright © 2011-2022 走看看