mikamatto/breadcrumbs-bundle 问题修复 & 功能扩展

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

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

mikamatto/breadcrumbs-bundle

Composer 安装命令:

composer require mikamatto/breadcrumbs-bundle

包简介

A Symfony bundle for managing breadcrumbs.

README 文档

README

Mikamatto\BreadcrumbsBundle is a Symfony bundle that provides easy-to-configure breadcrumbs functionality using a YAML file. It supports a simple, chain-based breadcrumb structure and includes caching for optimized performance.

Installation

Use Composer to install the bundle:

composer require mikamatto/breadcrumbs-bundle

Configuration

By default, the breadcrumbs configuration file should be located at config/packages/breadcrumbs.yaml. The structure inside this file should start with a breadcrumbs_bundle root key, as follows:

breadcrumbs_bundle:
  routes:
    app_page_index:
      label: 'Pages'

    app_page_edit:
      label: 'Edit Page'
      chain: ['app_page_index']

    app_page_new:
      label: 'New Page'
      chain: ['app_page_index']

    app_page_show:
      label: 'Page Details'
      chain: ['app_page_index']

Each route is defined by:

  • label: The breadcrumb label which will be rendered in the breadcrumb.
  • chain: Optional. Defines the chain of preceding routes (as an array of route names) which will be rendered recursively.

Custom File Path

If you prefer a custom file name, you can specify it in your configuration file as follows:

breadcrumbs_bundle:
  breadcrumbs_file: '%kernel.project_dir%/config/custom_breadcrumbs.yaml'
  routes:
    ...

Note: If you use a custom filename but do not specify it in the configuration, the bundle will work; however, caching will default to config/packages/breadcrumbs.yaml, which may lead to outdated breadcrumbs being displayed. Defining the path explicitly ensures cache invalidation occurs correctly.

This approach maintains flexibility while ensuring caching behaves as expected for any filename or location.

Usage

1. Twig Function

Use the Twig function getBreadcrumbs() to retrieve the breadcrumb chain for the current route.

{% for breadcrumb in getBreadcrumbs() %}
    <a href="{{ breadcrumb.url }}">{{ breadcrumb.label }}</a>
    {% if not loop.last %} > {% endif %}
{% endfor %}

This will output something like:

Home > Pages > Page Details

Note: To keep things lighter, the common root ‘Home’ can be hardcoded in Twig instead of being defined in each route chain.

2. Service: BreadcrumbsProcessor

You can also access the underlying service: the bundle exposes a BreadcrumbsProcessor service, which generates breadcrumb arrays for a given route.

Inject the service (Mikamatto\BreadcrumbsBundle\Service\BreadcrumbsProcessor) and call generateBreadcrumbs():

public function index(BreadcrumbsProcessor $breadcrumbsProcessor)
{
    $breadcrumbs = $breadcrumbsProcessor->generateBreadcrumbs('app_page_show', ['id' => 1]);
    // Result based on example YAML above:
    // [
    //     ['label' => 'Pages', 'url' => '/page/'],
    //     ['label' => 'Page Details', 'url' => '/page/1']
    // ]
}

Caching

The bundle caches the breadcrumbs YAML file for performance. When the YAML file changes, the cache automatically invalidates and updates. A dedicated cache pool is used, defined in your bundle’s service configuration.

Example Output

The output of getBreadcrumbs() in Twig (or generateBreadcrumbs() as a service) will look like this:

[
    ['label' => 'Pages', 'url' => '/page/'],
    ['label' => 'Page Details', 'url' => '/page/1']
]

Summary

  • Breadcrumbs YAML configuration defines route labels and chains.
  • Service BreadcrumbsProcessor generates breadcrumbs for specified routes.
  • Twig function getBreadcrumbs() automatically provides breadcrumbs for the current route.
  • Caching is automatically managed on YAML changes for optimized performance.

This structure allows you to integrate breadcrumbs easily with flexible customization options.

mikamatto/breadcrumbs-bundle 适用场景与选型建议

mikamatto/breadcrumbs-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-05