定制 rybakit/navigation-bundle 二次开发

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

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

rybakit/navigation-bundle

Composer 安装命令:

composer require rybakit/navigation-bundle

包简介

Navigation bundle for Symfony applications

README 文档

README

Build Status

Installation

The recommended way to install this bundle is through Composer:

$ composer require rybakit/navigation-bundle:~1.0@dev

After you have installed the package, include RybakitNavigationBundle to your kernel class:

public function registerBundles()
{
    $bundles = [
        ...
        new Rybakit\Bundle\RybakitNavigationBundle(),
    ];

    ...
}

Usage Examples

To see how to create a menu as a service and retrieve it from different parts of your application, follow the link: https://gist.github.com/rybakit/4491556.

Build a navigation tree

<?php

use Rybakit\Bundle\NavigationBundle\Navigation\Item;

$root = new Item('root');
$child = new Item('child');
$root->add($child);

$parent = $child->getParent(); // $root
$has = $root->has($child); // true
$root->remove($child);

Create a tree from an array

<?php

use Rybakit\Bundle\NavigationBundle\Navigation\ItemFactory;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\BindFilter;

...

$array = [
    'label'    => 'root',
    'children' => [
        ['label' => 'Item 1.1'],
        ['label' => 'Item 1.2', 'children' => [['label' => 'Item 1.2.1']]],
        ['label' => 'Item 1.3'],
    ],
];

$factory = new ItemFactory(new BindFilter());
$root = $factory->create($array);

Match the current item

// Acme/DemoBundle/Navigation/NavigationBuilder.php
<?php

namespace Acme\DemoBundle\Navigation;

use Rybakit\Bundle\NavigationBundle\Navigation\ItemFactory;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\BindFilter;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\FilterChain;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\MatchFilter;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\Matcher\RoutesMatcher;

class NavigationBuilder
{
    ...

    public function createNavigation()
    {
        $request = $this->requestStack->getMasterRequest();
        $route = $request->attributes->get('_route');
        $routeParams = $this->request->attributes->get('_route_params', []);

        $filter = new FilterChain([
            $matchFilter = new MatchFilter(new RoutesMatcher($route, $routeParams)),
            new BindFilter(),
        ]);

        $factory = new ItemFactory($filter);
        $root = $factory->create([
            'label'     => 'acme_demo.home',
            'route'     => 'acme_demo_home',
            'children'  => [
                [
                    'label'  => 'acme_demo.user_new',
                    'route'  => 'acme_demo_user_new',
                    'routes' => ['acme_demo_user_create'],
                ],
            ],
        ]);

        if (!$current = $matchFilter->getMatched()) {
            $current = $root;
        }
        $current->setActive();

        return ['root' => $root, 'current' => $current];
    }
}

Default item properties

<?php

use Rybakit\Bundle\NavigationBundle\Navigation\Item;
use Rybakit\Bundle\NavigationBundle\Navigation\ItemFactory;
use Rybakit\Bundle\NavigationBundle\Navigation\Filter\BindFilter;

...

$item = new Item();

// set translation domain to "AcmeDemoBundle" by default for all tree items
$item->transDomain = 'AcmeDemoBundle';

$factory = new ItemFactory(new BindFilter(), $item);
$root = $factory->create($array);

Twig

{# simple render #}
{{ nav(nav.root, "my_block_name", { "opt1": "val1", "opt2": "val2" }) }}

{# render using tree filter #}
{{ nav(nav.root|tree, "nav") }}

{# render using tree filter with max depth = 1 #}
{{ nav(nav.root|tree(1), "nav") }}

{# render only visible items, max depth = 1 #}
{{ nav(nav.root|tree(1)|visible, "nav") }}

{# render only hidden items #}
{{ nav(nav.root|tree|visible(false), "nav") }}

{# render breadcrumbs #}
{{ nav(nav.current|breadcrumbs, "breadcrumbs") }}

{# render breadcrumbs with custom title at the end #}
{{ nav(nav.current|breadcrumbs, "breadcrumbs", { "last": "Custom title" }) }}

{# get root #}
{{ nav.current|ancestor(0) }}

{# get second level ancestor #}
{{ nav.current|ancestor(2) }}

{# get parent #}
{{ nav.current|ancestor(-1) }}

{# render submenu #}
{{ nav(nav.current|ancestor(2)|tree(2)|visible, "navlist") }}

Customising the navigation template

# app/config/config.yml
rybakit_navigation:
    template: navigation.html.twig
# app/Resources/views/navigation.html.twig
{% extends 'RybakitNavigationBundle::navigation.html.twig' %}

# override the "nav" block
{% block nav %}
    <ul class="nav navbar-nav">{{ block('nav_items') }}</ul>
{% endblock %}

License

RybakitNavigationBundle is released under the MIT License. See the bundled LICENSE file for details.

rybakit/navigation-bundle 适用场景与选型建议

rybakit/navigation-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2012 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「menu」 「breadcrumbs」 「navigation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rybakit/navigation-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rybakit/navigation-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 rybakit/navigation-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-10-25