kayrault/breadcrumb-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kayrault/breadcrumb-bundle

最新稳定版本:v1.0.0

Composer 安装命令:

composer require kayrault/breadcrumb-bundle

包简介

README 文档

README

License: MIT

Breadcrumb navigation management for Symfony applications.

This bundle provides a simple, flexible way to define and render breadcrumbs in Symfony 7.3+ using KnpMenu and Twig. It ships with a configuration system, ready‑to‑use templates, and translations to help you get productive quickly.

  • Compatible with: Symfony 7.3+ and PHP 8.3+
  • Depends on: symfony/framework-bundle, symfony/translation, twig/twig, knplabs/knp-menu-bundle

Installation

1) With Symfony Flex (recommended)

composer require kayrault/breadcrumb-bundle

Flex will register this bundle and usually enable KnpMenuBundle, and wire services automatically.

Note: In some Symfony Flex setups, you may need to enable KnpMenuBundle manually in config/bundles.php (see the bundles.php snippet below).

2) Without Symfony Flex

  1. Require the packages:
    composer require kayrault/breadcrumb-bundle knplabs/knp-menu-bundle
  2. Enable the bundles in config/bundles.php:
    return [
        // ...
        Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
        Kayrault\BreadcrumbBundle\KayraultBreadcrumbBundle::class => ['all' => true],
    ];

No additional service config is needed: the bundle ships its own service definitions and Twig path. The KnpMenuBundle must be enabled because this bundle registers its breadcrumb builder and renderer using KnpMenu services and tags.

Basic usage

The bundle exposes a KnpMenu builder and a renderer under the alias "kayrault_breadcrumb".

  • Menu builder service: Kayrault\BreadcrumbBundle\Menu\BreadcrumbBuilder
  • Renderer service: Kayrault\BreadcrumbBundle\Menu\BreadcrumbRenderer (KnpMenu renderer alias: kayrault_breadcrumb)
  1. Declare your breadcrumb items per route (see Configuration below).

  2. Render the breadcrumb in Twig:

{# e.g. templates/base.html.twig #}
{% if app.request %}
    {{ knp_menu_render('kayrault_breadcrumb', {}, 'kayrault_breadcrumb') }}
{% endif %}
  1. Include the stylesheet in your base layout so the breadcrumb renders with the default styles:
{# e.g. templates/base.html.twig, in your <head> block #}
<link rel="stylesheet" href="{{ asset('bundles/kayraultbreadcrumb/assets/styles/breadcrumb.css') }}">

This will use the bundle template @KayraultBreadcrumb/menu/breadcrumb.html.twig by default.

Programmatic building

This bundle focuses on configuration-driven breadcrumbs. If you need to build or manipulate menus programmatically, please use KnpMenuBundle directly (see https://github.com/KnpLabs/KnpMenuBundle for documentation).

Configuration

Define your breadcrumbs per route under the kayrault_breadcrumb root key. Each route contains an items list. Each item can be translated and optionally linked to a route.

# config/packages/kayrault_breadcrumb.yaml
kayrault_breadcrumb:
  # Optional: configure the Home entry (added automatically as the first item)
  home_route: 'app_home'
  home_label: 'kayrault_breadcrumb.common.home'
  home_translatable: true
  home_translation_domain: 'KayraultBreadcrumbBundle'

  routes:
    app_dashboard:
      items:
        - { label: 'Dashboard', translatable: true, translation_domain: 'messages' }
    app_article_show:
      items:
        - { label: 'menu.articles', translatable: true, translation_domain: 'messages', route: 'app_article_index' }
        - label: 'article.show'
          translatable: true
          translation_domain: 'messages'
          translation_parameters:
            - { key: '%name%', value: 'Acme' }

Notes:

  • The builder adds a "home" item by default. You can customize it with the home_* options above. If home_translatable is true, the label is translated using home_translation_domain.
  • Item fields:
    • label (string, required)
    • route (string|null)
    • translatable (bool, default: true)
    • translation_domain (string|null, default: messages when translatable)
    • translation_parameters (list of key/value pairs)

Assets and templates

  • Default template: @KayraultBreadcrumb/menu/breadcrumb.html.twig
  • Optional CSS provided at public/assets/styles/breadcrumb.css (publish or import in your asset pipeline if desired).

Documentation

Full documentation lives in the docs/ folder of this repository. Start with docs/ to explore advanced usage, template overrides, and customization.

Contributing

Contributions are welcome! Please:

  • Follow PSR-12 and Symfony coding standards.
  • Run quality tools before opening a PR:
  • Describe your change and include tests when applicable.

License

This bundle is released under the MIT License. See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固