定制 bkoetsier/navigation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bkoetsier/navigation

Composer 安装命令:

composer require bkoetsier/navigation

包简介

README 文档

README

Build Status

Navigation

After filling the navigation with your menu / breadcrumb - information (e.g. categories or whatever), you´re able to create a fully rendered HTML list.

Installation

Pull in the package with composer:

{
    "require": {
                "bkoetsier/navigation": "1.0.*"
                }
}

Laravel user

If you´re using the Laravel framework, all you have to do is reference the service provider and you are ready to go !

// app/config/app.php

'providers' => [
    '...',
    'Bkoetsier\Navigation\Providers\Laravel\NavigationServiceProvider',
];

Without Laravel

If you aren´t using Laravel, you have to wire up the package yourself:

use Bkoetsier\Navigation\Navigation;
use Illuminate\Support\Collection;

$nav = new Navigation(new Bucket(new Collection));

In case of using Laravel Navigation is shared via the IoC Container, so if you hydrate a bucket once, the bucket will be available all over your app, but the main difference is in instantiation

Basic usage

First step is always hydrating the bucket. To do so, you have to provide an array of objects (preferably StdClass) with the following properties:

  • itemId unique identifier like the database index
  • itemContent the content that should be rendered for this item
  • parentId identifier of the parent

In the fill method you are able to rename each parameter to your corresponding properties :

$example = [
    [
        "id": 1,
        "content": '<a href="/books">Books</a>',
        "parent": null,
    ],
    [
        "id": 2,
        "content": '<a href="/books/fiction">Fiction</a>',
        "parent": 1,
    ]
];
// array to \Std
$data = json_decode(json_encode($example));

// with Laravel
Nav::fill($data, $itemIdentifier = 'id', $itemContent ='content',$parentIdentifier = 'parent');

//without Laravel
$nav->fill($data, $itemIdentifier = 'id', $itemContent = 'content',$parentIdentifier = 'parent');

After hydrating you have to set the current item-id and call the render-method:

//with Laravel
// set the current active item-id, maybe from a url or db
Nav::setCurrent(2);
Nav::menu('main')->render();

//without Laravel
$nav->setCurrent(2);
$nav->menu('main')->render();

Attention: when you use php Nav::setCurrent() it will be set for each menu you have defined !

will output:

<ul>
    <li>
    <a href="/books">Books</a>
    <ul>
        <li>
        <span class="active"><a href="/books/fiction">Fiction</a></span>
        </li>
    </ul>
    </li>
</ul>

Please note that the current item will be wrapped in a span.active for additional styling Books has a Level of 1

Books has a Level of 1 not 0 !

If you have multiple navigation on your site you can set different states for each one:

Nav::menu('main')->setCurrent(1)->setMaxLevel(1);
Nav::menu('sub')->setCurrent(2);

//will render until level == 1 from id 1 down
Nav::menu('main')->render();
// will render from id 2 down until the end
Nav::menu('sub')->render();

For the breadcrumbs you just call the same bucket:

//with Laravel
Nav::breadcrumbs()->render();

//without Laravel
$nav->breadcrumbs()->render();

统计信息

  • 总下载量: 69
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固