Yii2菜单小部件禁用父项链接

时间:2018-04-27 07:48:52

标签: yii2-advanced-app yii2-widget

如何仅禁用父项链接并使其子项可单击?例如 - 当我点击我的父母时,它应该打开子菜单而不是重定向到其他地方。如果我点击儿童,它应该重定向我。 P.S我红了文档,搜索谷歌,但没有任何结果。 这是我的代码:

<?php

use backend\models\PageAdmin;
use backend\helpers\BackendPrefix;
use yii\widgets\Menu;

$menu_pages = PageAdmin::find()->where('active=1 AND id_in IS NULL')->all();

$widget_menu_content = [];

foreach ($menu_pages as $key => $page){

    $related_pages = PageAdmin::find()->where(['active' => 1, 'id_in' => $page->id])->all();
    $widget_menu_content[$key]['label'] = "<i class='{$page->icon}'></i>";
    $widget_menu_content[$key]['icon'] = $page->icon;
    $widget_menu_content[$key]['url'] = BackendPrefix::PREFIX .'/'. $page->url;

    if(!empty($related_pages)){

        foreach ($related_pages as $key2 => $rel_page) {

            $widget_menu_content[$key]['items'][$key2]['label'] = $rel_page->title;
            $widget_menu_content[$key]['items'][$key2]['icon'] = "caret-right";
            $widget_menu_content[$key]['items'][$key2]['url'] = BackendPrefix::PREFIX . "/" . $rel_page->url;

        }

    }
}

?>

<div class="side-mini-panel">
    <?=

        Menu::widget([
            'encodeLabels' => false,
            'options' => [
                'class' => 'mini-nav',
            ],
            'activeCssClass' => 'selected',
            'items' => $widget_menu_content,
            'submenuTemplate' => "
                                \n<div class='sidebarmenu'>
                                    \n<h3 class='menu-title'>{label}</h3>
                                    \n<div class='searchable-menu'>
                                    \n<form role='search' class='menu-search'>
                                        \n<input type='text' placeholder='Search...' class='form-control' />
                                        \n<a href='javascript:void(0)'><i class='fa fa-search'></i></a>
                                    \n</form>
                                    \n<div>
                                    \n<ul class='sidebar-menu'>
                                        \n{items}
                                    \n</ul>
                                \n</div>",
            'linkTemplate' => "<a href='javascript:void(0)'>{label}</a>",
            'activateParents' => true,
        ])

    ?>
</div

Whit 'linkTemplate'我禁用显然不是我的目标的所有链接:)(它应该仅禁用父母)。 Alsom,有什么标记(或其他一些选项,因为我认为items是孩子们唯一的标记)我应该在这一行上附加子项标签:\n<h3 class='menu-title'>{label}</h3>。在我的情况下,我得到回应的只是{label}就像一个字符串。 非常感谢!

0 个答案:

没有答案