cnerta / breadcrumb-bundle
此包已被废弃且不再维护。未建议替换包。
CnertaBreadcrumbBundle,为Symfony2提供了一种简单的方式来创建带有KnpMenuBundle的面包屑。
2.1.1
2015-10-21 15:36 UTC
Requires
- knplabs/knp-menu-bundle: ~2.0
- symfony/framework-bundle: >2.1
Requires (Dev)
- knplabs/knp-menu-bundle: ~2.0
- phpunit/phpunit: ~4.8
- symfony/symfony: 2.7.*
This package is not auto-updated.
Last update: 2020-01-24 15:01:49 UTC
README
CnertaBreadcrumbBundle
CnertaBreadcrumbBundle 为 Symfony2 提供了一种简单的方式来创建带有 KnpMenuBundle 的面包屑。
如果您想查看,这个 Symfony2 应用是我的沙盒,DemoMenu。
安装包
- 在您的 composer.json 中添加源
"require": { // ... "cnerta/breadcrumb-bundle": "2.1.*" }
- 然后将其添加到您的 AppKernel 类中:
// in AppKernel::registerBundles() $bundles = array( // ... new Cnerta\BreadcrumbBundle\CnertaBreadcrumbBundle(), // ... );
默认配置
您不需要配置任何东西。这部分仅在您想要设置默认的面包屑模板时有用。
config.yml
cnerta_breadcrumb: twig: template: CnertaBreadcrumbBundle::cnerta_breadcrumb.html.twig
渲染面包屑
首先使用 KnpMenuBundle 创建您的菜单。
接下来,在您的 twig 模板中调用
{{ cnerta_breadcrumb_render('MyWonderfullBundle:Builder:Menu') }}
或者如果您只想获取面包屑数组并自己处理
{% set currentItem = cnerta_breadcrumb_get('MyWonderfullBundle:Builder:Menu') %} {# some crazy stuff #} {% for item in currentItem %} {% if loop.index != 1 %} {% if loop.index > 1 %} > {% endif %} {% if not loop.last %}<a href="{{ item.uri }}">{{ item.label }}</a> {% else %}<span>{{ item.label }}</span>{% endif %} {% endif %} {% endfor %}
如果您想使用自己的模板来渲染
{{ cnerta_breadcrumb_render('MyWonderfullBundle:Builder:Menu', {'template': 'MyWonderfullBundle:Breadcrumb:myBreadcrumb.html.twig'}) }}
单元测试包
在运行 phpunit 之前,您必须加载依赖。这将仅加载运行测试所需的必需的供应商。
composer install --dev
之后,您可以运行 phpunit。
./vendor/bin/phpunit -c phpunit.xml.dist
更新日志
版本 2.1.0 (2015/10/19)
- #4 删除了一个不必要的函数,该函数删除了一个标记为 "root" 的节点