欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

自己亲自做的面包屑 breadcrumbs 有大用

如何安装面包屑,见 /node-admin/9494        /node-admin/9498

<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/1
 * Time: 14:02
 */
// Home
Breadcrumbs::register('index', function($breadcrumbs)
{
    $breadcrumbs->push('网站首页', route('index'));
});

Breadcrumbs::register('categorys.show', function($breadcrumbs,$category)
{
    $breadcrumbs->parent('index');
    foreach($category->getParents() as $parent){
        $breadcrumbs->push($parent->name, route('categorys.show', $parent->id));
    }
//var_dump($parent->name);
    $breadcrumbs->push($category->name, route('categorys.show',$category->id));
});
// Home > Blog
Breadcrumbs::register('articles.show', function($breadcrumbs,$article,$curr_area_name='')
{

    $breadcrumbs->parent('categorys.show',$article->category);
    //$breadcrumbs->push($article->article_title, route('articles.show',$article->article_id));
    $breadcrumbs->push($curr_area_name.$article->article_title, route('articles.show',$article->article_id));
});

Breadcrumbs::register('searchs.show', function($breadcrumbs,$search)
{
    $breadcrumbs->parent('index');

    $breadcrumbs->push($search);

//var_dump($parent->name);

});

?>



blade.php 模板视图中

    <div class="site">您的当前位置:

        {!! Breadcrumbs::render('categorys.show',$curr_category)  !!}

    </div>




如果需要额外的变量  在 App\Http\breadcrumbs.php 中定义一个全局变量

image.png.


在 breadcrumbs的 模板 bootstrap3.blade.php 中获取这个全局变量

image.pngimage.png



普通分类: