Yii2中的多级菜单使用Bootstrap

时间:2018-01-30 12:14:59

标签: css twitter-bootstrap twitter-bootstrap-3 yii2

我的代码需要帮助,因为我无法创建多级菜单。这是我的代码。

    <div class="collapse navbar-collapse">
                        <ul class="nav navbar-nav">

                            <?php
                            foreach ($getMenuList as $item) {
                                $page_name = str_replace(' ', '-', $item['page_name']);
                                //$category = str_replace(' ', '-', $item['category']);
                                $focus_areaid = 0;
                                if (!empty($item['focus_areaid'])) {
                                    $focus_areaid = $item['focus_areaid'];
                                }
                                ?>


                                <li class="<?= (empty($getSubMenuList[$item['page_id']])) ? '' : 'dropdown'; ?>">
                                    <?php $url = ['society/index', 'PageName' => $page_name]; ?>

                                    <?php if ((empty($getSubMenuList[$item['page_id']]))) { ?>
                                        <a href="<?= Url::to($url) ?>">
                                        <?php } else { ?>
                                            <a href="<?= Url::to($url) ?>" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                            <?php } ?>
                                            <?= $item['page_name']; ?>
                                            <?php if (!empty($getSubMenuList[$item['page_id']])) { ?>
                                                <span class="caret"></span>
                                            <?php } ?>
                                        </a>

                                        <?php if (!empty($getSubMenuList[$item['page_id']])) { ?>
                                            <ul class="dropdown-menu dropdown-content dropdown-toggle">
                                                <?php
                                                foreach ($getSubMenuList[$item['page_id']] as $key => $i) {
                                                    $page_name = str_replace(' ', '-', $i['page_name']);
                                                    $focus_areaid = 0;
                                                    if (!empty($i['focus_areaid'])) {
                                                        $focus_areaid = $i['focus_areaid'];
                                                    }
                                                    // $category = str_replace(' ', '-', $i['category']);
                                                    ?>
                                                    <li>
                                                        <?= Html::a($i['page_name'], ['society/index', 'PageName' => $page_name]) ?>
                                                        </li>
                                                <?php } ?>
                                            </ul>
                                        <?php } ?>
                                </li>

                            <?php } ?>
</ul>

我希望它是三级菜单,但目前它只显示2级菜单。 enter image description here

我没有得到我错的地方。请帮帮我

public static function menuList() {
    $sql = "SELECT page_id,page_name,focus_areaid,category FROM sas_pages where (parent=0 or parent IS NULL) and display_nav=1 and is_publish=1 and is_active=1";
    $output = \Yii::$app->db->createCommand($sql)->queryAll();
    return $output;

}

public static function subMenuList() {
    $sql = "SELECT page_id,page_name,category FROM sas_pages where (parent=0 or parent IS NULL) and display_nav=1 and is_publish=1 and is_active=1";
    $output = \Yii::$app->db->createCommand($sql)->queryAll();
    //print_r($output);

    foreach($output as $item){
       $subMenu=$item['page_id'];
       $menu=$item['page_name'];
       $sql = "SELECT page_id,page_name,parent,focus_areaid,category FROM sas_pages WHERE parent = '$subMenu' and is_publish=1 and is_active=1";
       $mainOutput[$subMenu] = \Yii::$app->db->createCommand($sql)->queryAll();
    }

    if (!empty($mainOutput)) {
       return $mainOutput;
        // print_r(ArrayHelper::map($mainOutput, 'parent', 'child'));
    }
    return null;
}

这是我的条件和控制器。如果需要,请提供代码,以便我能够处理它

0 个答案:

没有答案