后台框架ace,目录数据由后台配置,视图界面再读取数据渲染,记之…

目录数据配置
sidebar.php

<?php
/**
 * 后台侧栏导航配置
 */
return [
    'sidebarItems' => [
        'index' => [
            "link" => '?r=index/index',
            "title" => "控制台",
            "icon" => "fa fa-tachometer"
        ],
        'goods' => [
            "open" => "",
            "link" => null,
            "title" => "商品管理",
            "icon" => "fa fa-desktop",
            "submenu" => [
                'goods-list' => [
                    "link" => '?r=goods/goods/goods-list',
                    "title" => "商品列表",
                    "icon" => "fa fa-caret-right",
                ],
                'goods-add' => [
                    "link" => '?r=goods/goods/goods-add',
                    "title" => "添加新商品",
                    "icon" => "fa fa-caret-right",
                ],
                'category-list' => [
                    "link" => '?r=goods/category/category-list',
                    "title" => "商品分类",
                    "icon" => "fa fa-caret-right",
                ],
                'brand-list' => [
                    "link" => '?r=goods/brand/brand-list',
                    "title" => "商品品牌",
                    "icon" => "fa fa-caret-right",
                ],
                'type-list' => [
                    "link" => '?r=goods/type/type-list',
                    "title" => "商品类型",
                    "icon" => "fa fa-caret-right",
                ],
            ]
        ],
        'store' => [
            "open" => "",
            "link" => null,
            "title" => "商城管理",
            "icon" => "glyphicon glyphicon-list",
            "submenu" => [
                'scroll-list' => [
                    "link" => '?r=store/scroll/scroll-list',
                    "title" => "首页轮播图",
                    "icon" => "fa fa-caret-right",
                ]
            ]
        ]
    ]
];

视图渲染部分

<ul class="nav nav-list">

<?php
    function genOneLi($item) {
        if(empty($item)) return '';
        $htmlFormat = '<li class="%s %s">
                            <a href="%s" class="%s">
                                <i class="menu-icon %s"></i>
                                <span class="menu-text"> %s </span>
                                %s
                            </a>
            
                            <b class="arrow"></b>
                            %s
                        </li>';
        $itemHtml = sprintf($htmlFormat, empty($item['open'])?'':'open active',empty($item['active'])?'':'active',
            $item['link'], empty($item['submenu'])?'':'dropdown-toggle',
            empty($item['icon'])?'':$item['icon'], $item['title'],empty($item['submenu'])?'':'<b class="arrow fa fa-angle-down"></b>', empty($item['submenu'])?'':genSubmenu($item));
        return $itemHtml;
    }

    function genSubmenu($item) {
        $submenu = '<ul class="submenu">';
        foreach ($item['submenu'] as $ii) {
            $submenu .= genOneLi($ii);
        }
        return  $submenu . '</ul>';
    }
?>

<?php foreach ($this->params['sidebarItems'] as $key=>$item): ?>
    <li class="<?= empty($item['open'])?'':'open active' ?> <?= empty($item['active'])?'':'active' ?>">
        <a href="<?= $item['link'] ?>" class="<?= empty($item['submenu'])?'':'dropdown-toggle' ?>">
            <i class="menu-icon <?= $item['icon'] ?>"></i>
            <span class="menu-text"> <?= $item['title'] ?> </span>
            <?= empty($item['submenu'])?'':'<b class="arrow fa fa-angle-down"></b>' ?>
        </a>

        <b class="arrow"></b>
    <?php if(!empty($item['submenu'])): ?>
        <?= genSubmenu($item) ?>
    <?php endif;?>
    </li>
<?php endforeach;?>
</ul><!-- /.nav-list -->

分类: PHP

发表评论

电子邮件地址不会被公开。 必填项已用*标注