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;
    }
    }
     
    你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
  • 相关阅读:
    Days like that:
    获取网站访问来源URL
    论坛里面的一个帖子
    Days like that:
    简单项目布署
    论坛里面的一个帖子
    获取网站访问来源URL
    piwik开放源代码的Web统计软件
    p标签里面不能嵌套div
    IO操作 第二篇 学习(转载)
  • 原文地址:https://www.cnblogs.com/stj123/p/9787401.html
Copyright © 2011-2022 走看看