zoukankan      html  css  js  c++  java
  • Yii2 使用小部件 Breadcrumbs

    yii有两种Breadcrumbs写法,
    one:

    echo Breadcrumbs::widget([
        'itemTemplate' => "<li><i>{link}</i></li>
    ", // template for all links
        'links' => [
            [
                'label' => 'Post Category',
                'url' => ['post-category/view', 'id' => 10],
                'template' => "<li><b>{link}</b></li>
    ", // template for this link only
            ],
            ['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]],
            'Edit',
        ],
    ]);
    

    two:

    echo Breadcrumbs::widget([
        'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
    ]);
    

    第二种在yii的main.php中用实例,就是最简单home->edit;

    今天将要说的第一种,

    echo Breadcrumbs::widget([
    	'itemTemplate' => "<li><i>{link}</i></li>
    ", // template for all links
    	'links' => $link,
    ]);
    

    由于此处需要使用breadcrumbs展现相应的tree结构,经过对link中的数据进行重组可以将程序写成上面的样子,

    if (!empty($title)) {
        $title = $title;
        $title_arr = explode('/', $title);
        foreach ($title_arr as $k => $item) {
            if (!empty($item)) {
                $link[] = ['label' => $item, 'url' => ['/tree/edit/', 'id' => $item, 'type' => 1,]];
            }
        }
        $title_s = '';
        foreach ($link as $k => $item) {
            if ($k !== 0) {
                if ($k === 1) {
                    $title_s = $link[$k - 1]['label'];
                } else {
                    $title_s = $title_s . '/' . $link[$k - 1]['label'];
                }
                $link[$k] = ['label' => $item['label'], 'url' => ['/tree/edit/', 'id' => $item['label'], 'type' => 1, 'title' => $title_s]];
            } else {
                $title_s = $item['label'];
            }
        }
        $title = $title . '/' . $node_id['nodeId'];
    } else {
        $title = $node_id['nodeId'];
    }
    $link[] = $node_id['nodeId'];
    

    这样就展示了一个tree的结构

  • 相关阅读:
    双链表 teacherboubleloopnohead
    System.Reflection(温习二)
    在地址栏调试js(小技巧)
    在vs2005中的ReportViewer(RDLC报表)中使用直接打印功能,在vs2005使用ReportViewer2008
    .net的手动编译类方法
    System.Reflection(温习)
    https://imo.im/
    SOA是什么(转)
    ASP.NET的编译方法(转,复习一下)
    动态生成一个继承接口的类
  • 原文地址:https://www.cnblogs.com/grimm/p/5825796.html
Copyright © 2011-2022 走看看