Blogger Information
Blog 35
fans 0
comment 0
visits 26670
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用后台管理分类,读取出来,整理成为二级菜单,循环菜单数据。
锋芒天下的博客
Original
721 people have browsed it

实例

<?php


namespace app\admins\controller;



use think\facade\Db;
use think\facade\View;


class Home
{
    public function index(){
       $menus = Db::table('admin_menus')->order('pid')->select();
       $data = [];
       foreach ($menus as $v){
           if ($v['pid'] == 0){
               $data[$v['mid']] = $v;
           }else{
               $data[$v['pid']]['s'][] = $v;
           }
       }

//       print_r($data);
//       exit();

        View::assign('menus',$data);
        return view();
    }
    public function welcome(){
        return view();
    }
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!DOCTYPE html>
<html>
<head>
    <title>cms后台管理系统</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
    <style type="text/css">
        .header{width:100%;height: 50px;line-height: 50px;background: #2e6da4;color:#ffffff;}
        .title{margin-left: 20px;font-size: 20px;}
        .userinfo{float: right;margin-right: 10px;}
        .userinfo a{color:#ffffff;}
        .menu{width: 200px;background: #333744;position: absolute;}
        .main{position: absolute;left: 200px;right: 0px;}

        .layui-collapse{border: none;}
        .layui-colla-item{border-top: none;}
        .layui-colla-title{background: #42485b;color:#ffffff;}
        .layui-colla-content{border-top: none;padding: 0px;}
    </style>
</head>
<body>
<!--header-->
<div class="header">
    <span class="title"><span style="font-size: 20px;"></span>--后台管理系统</span>
    <span class="userinfo"><span><a href="javascript:;" onclick="logout()">退出</a></span></span>
</div>
<!--菜单-->
<div class="menu" id="menu">
    <div class="layui-collapse" lay-accordion>
        {foreach $menus as $menu}
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">{$menu['title']}</h2>
            <div class="layui-colla-content">
                {foreach $menu['s'] as $m}
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item"><a href="javascript:;" onclick="menuFire(this)" src="">{$m['title']}</a></li>
                </ul>
                {/foreach}
            </div>
        </div>
        {/foreach}

    </div>
</div>
<!--主操作页面-->
<div class="main">
    <iframe src="/index.php/admins/home/welcome" onload="resetMainHeight(this)" style="width: 100%;height: 100%;" frameborder="0" scrolling="0"></iframe>
</div>

<script>
    layui.use(['element','layer'], function(){
        var element = layui.element;
        $ = layui.jquery;
        layer = layui.layer;

        resetMenuHeight();
    });

    // 重新设置菜单容器高度
    function resetMenuHeight(){
        var height = document.documentElement.clientHeight - 50;
        $('#menu').height(height);
    }

    // 重新设置主操作页面高度
    function resetMainHeight(obj){
        var height = parent.document.documentElement.clientHeight - 53;
        $(obj).parent('div').height(height);
    }

    // 菜单点击
    function menuFire(obj){
        // 获取url
        var src = $(obj).attr('src');
        // 设置iframe的src
        $('iframe').attr('src',src);
    }

</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments