zoukankan      html  css  js  c++  java
  • 递归

    public function _initialize()
    {
    if (!Session::has('user', 'think')) {
    $this->error('您还没有登录', 'Login/index');
    }
    }

    public function index()
    {
    $value=Session::get("user","think");
    $uid=$value["uid"];
    $data = Db::query("select * from access where aid in (select a_id from r_a where r_id in (select r_id from u_r where u_id=$uid))");
    $res=$this->digui($data);
    Session::set("access",$res,"think");
    return view("index",['list'=>$res,'data'=>$value]);
    }

    public function digui($data,$level=0,$pid=0){
    static $array=array();
    foreach($data as $k=>$v){
    if($v['pid']==$pid){
    $v['level']=$level;
    $v['url']=$v['controller_name']."/".$v['action_name'];
    $array[]=$v;
    $this->digui($data,$level+1,$v['aid']);
    }
    }
    return $array;
    }

    //join查询递归

    $data=Db::table("user")
    ->join('user_role','user.uid=user_role.u_id')
    ->join('role','user_role.r_id=role.rid')
    ->join('role_node','role.rid=role_node.r_id')
    ->join('node','role_node.n_id=node.nid')
    ->select();
    //print_r($data);
    $arr=[];
    foreach($data as $k=>$v){
    $arr['uid']=$v['uid'];
    $arr['uname']=$v['username'];
    $arr['role_name']=$v['r_name'];
    $arr['one_menu'][]=['n_name'=>$v['n_name'],'n_url'=>$v['n_url'],'pid'=>$v['pid'],'n_id'=>$v['nid']];
    }
    // print_r($arr);
    foreach($arr['one_menu'] as $kk =>$vv){
    $res =Db::table("node")->where("pid=".$vv['n_id'])->select();
    $arr['one_menu'][$kk]['two_menu'] =$res;
    }
    // print_r($arr);
    return view("home",['list'=>$arr]);


    <a href="index.html">退出</a>
    <p>当前登录账号:{$list.uname}</p>
    <p>当前登录账号:{$list.role_name}</p>
    <p>权限:</p>
    <div>
    <ul class="one">
    {volist name="list.one_menu" id="v"}
    <li><a href="{$v.n_url}" class="cli">{$v.n_name}</a></li>
    <div style="display: none">
    <ul>
    {volist name="v.two_menu" id="vo"}
    <li class="two"><a href="{$vo.n_url}">{$vo.n_name}</a></li>
    {/volist}
    </ul>
    </div>
    {/volist}
    </ul>
    </div>
    </body>
    </html>
    <script src="__STATIC__/js/jq.js"></script>
    <script>
    $(document).ready(function(){
    $(".cli").click(function(){
    $(this).parent().next("div").slideToggle();
    });
    });

  • 相关阅读:
    人民币大小写转换
    window.parent与window.openner区别
    jquery.honver(),toggle()
    ADO.NET Entity Framework 之“无法加载指定的元数据资源。”
    window.external 的用法(收藏夹功能)
    空链接的技巧
    IIS自动开通组件编程
    在Asp.net中操作IIS的虚拟目录(C#)
    最佳 .NET 网站推荐
    边框 top、clientTop、scrollTop、offsetTop
  • 原文地址:https://www.cnblogs.com/gwhm/p/10223673.html
Copyright © 2011-2022 走看看