qiuxis 2016-12-20 21:43:50 528次浏览 0条回复 4 3 0
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/14
 * Time: 16:59
 */

namespace backend\controllers;

use yii\base\Controller;
use yii\widgets\Menu;

class WidgetController extends  Controller
{
    public function actionIndex()
    {
        return '';
    }

///////////////////////////////////////////////////////////////////
ta.jpg

    public function actionMenuTa()
    {
        echo Menu::widget([
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                ['label' => 'DDD', 'url' => ['widget/menu-tb']],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
tb.jpg

    /*
     * activateItems bool , 为全局参数,默认是 true
     * active bool , 为局部参数,默认为 false
     * activeCssClass string , 默认为 'active'
     * */
    public function actionMenuTb()
    {
        echo Menu::widget([
            'activateItems' => false, //默认是 true
            'activeCssClass'=>'act',
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label'     => 'DDD',
                    'url'       => ['widget/menu-tb'],
                    'active'    => true, // 默认是 false
                ],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
tc.jpg

    /**
     * firstItemCssClass, lastItemCssClass items 的前和尾 css class 名称
     * 这里需要注意,子 items 也会加入
     */
    public function actionMenuTc()
    {
        echo Menu::widget([
            'firstItemCssClass'=>'fistitemclass',
            'lastItemCssClass' =>'lastitemclass',
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                ['label' => 'DDD', 'url' => ['widget/menu-tb']],
                [
                    'label'     => 'EEE',
                    'visible'   => false,
                ],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
td.jpg

    public function actionMenuTd()
    {
        echo Menu::widget([
            'options' => [
                'class' => 'navbar-nav nav',
                'id'=>'navbar-id',
                'style'=>'font-size: 14px;',
                'data-tag'=>'yii2-menu',
            ],
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                ['label' => 'DDD', 'url' => ['widget/menu-tb']],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
te.jpg

    public function actionMenuTe()
    {
        echo Menu::widget([
            //public $linkTemplate = '<a href="{url}">{label}</a>';
            'linkTemplate' => '<a href="{url}"><span>{label}</span></a>',
            'labelTemplate' =>'<i>{label}</i>',
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label' => 'DDD',
                    'url' => ['widget/menu-tb'],
                    'template' => '<a href="{url}" >{label}<i class="fa fa-angle-left pull-right"></i></a>',
                ],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
tf.jpg

    public function actionMenuTf()
    {
        echo Menu::widget([
            'encodeLabels' => false, // 全局参数 默认为 true
            'items'     => [
                [
                    'label' => '<i>AAA</i>',
                    'encode'    => true, // 全局参数 默认为 false
                    'url' => 'http://www.baidu.com'
                ],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                ['label' => 'DDD', 'url' => ['widget/menu-tb']],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
tg.jpg

    public function actionMenuTg()
    {
        echo Menu::widget([
            'activateParents' => true, //默认为 false
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label' => 'DDD',
                    'url'   => ['widget/menu-tb'],
                    'items' => [
                        [
                            'label' => 'ddd1',
                            'url' => '#',
                            'items' => [
                                ['label' => 'ss'],
                            ],


                        ],
                        ['label' => 'ddd2', 'url' => ['widget/menu-tg']],
                        ['label' => 'ddd3', 'url' => '#'],
                    ]
                ],
                ['label' => 'EEE'],
            ]
        ]);
    }

///////////////////////////////////////////////////////////////////
th.jpg

    public function actionMenuTh()
    {
        echo Menu::widget([
            'itemOptions'=> [
                'class'=>'item_class',
                'style'=>'font-weight:bold'
            ],
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label' => 'DDD',
                    'url'   => ['widget/menu-tb'],
                    'items' => [
                        ['label' => 'ddd1', 'url' => '#'],
                        ['label' => 'ddd2', 'url' => ['widget/menu-tg']],
                        ['label' => 'ddd3', 'url' => '#'],
                    ]
                ],
                ['label' => 'EEE'],
            ],
        ]);
    }

///////////////////////////////////////////////////////////////////
ti.jpg

    public function actionMenuTi()
    {
        echo Menu::widget([
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label' => 'DDD',
                    'url'   => ['widget/menu-tb'],
                    'options'   => [
                        'class' => 'sxx',
                        'id'    =>'navbar-id2',
                        'style'=>'font-size: 12px;',
                        'data-tag'=>'yii2-menu',
                    ],
                    'items' => [
                        ['label' => 'ddd1', 'url' => '#'],
                        ['label' => 'ddd2', 'url' => '#'],
                        ['label' => 'ddd3', 'url' => '#'],
                    ]
                ],
                ['label' => 'EEE'],
            ],
        ]);
    }

///////////////////////////////////////////////////////////////////
tj.jpg

    public function actionMenuTj()
    {
        echo Menu::widget([
            'submenuTemplate' => "\n<ul class='treeview-menu' role='menu'>\n{items}\n</ul>\n",
            'items'     => [
                ['label' => 'AAA', 'url' => 'http://www.baidu.com'],
                ['label' => 'BBB', 'url' => ['site/index', 'tag'=>'xx']],
                ['label' => 'CCC', 'url' => ['widget/menu-ta']],
                [
                    'label' => 'DDD',
                    'url'   => ['widget/menu-tb'],
                    'options'       => [
                        'class'     => 'sxx',
                        'id'        => 'navbar-id2',
                        'style'     => 'font-size: 12px;',
                        'data-tag'  => 'yii2-menu',
                    ],
                    'items' => [
                        ['label' => 'ddd1', 'url' => '#'],
                        ['label' => 'ddd2', 'url' => '#'],
                        ['label' => 'ddd3', 'url' => '#'],
                    ]
                ],
                ['label' => 'EEE'],
            ],
        ]);
    }

///////////////////////////////////////////////////////////////////

    public function actionMenuTk()
    {
        echo Menu::widget(
            [
                'activateItems' => true,
                'route' => 'widget/menu-tk',
                'params' => [
                    'tag' => 'ss'
                ],
                'items'         =>[
                    [
                        'label' => 'Action',
                        'url' => ['widget/menu-tk', 'tag' => 'ss'],
                    ],
                    ['label' => 'Another action','url' => '/index.php'],
                    ['label' => 'Something else here', 'url' => '#'],
                ],
            ]
        );
    }

}
觉得很赞
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册
在线
361