rollerworks / navigation-bundle
Symfony 插件,用于在 KnpMenuBundle 中定义菜单结构和面包屑导航
Requires
- php: >=5.3
- knplabs/knp-menu-bundle: ^2.0.0
- symfony/dependency-injection: ~2.4|~3.0
- symfony/expression-language: ~2.4|~3.0
- symfony/framework-bundle: ~2.3|~3.0
Requires (Dev)
README
⚠️ ✋ 此插件已废弃并将很快存档!⚠️
RollerworksNavigationBundle 允许你在应用配置中定义 KnpMenuBundle 的菜单结构和面包屑导航。
要求
您需要至少 PHP 5.3,并且已经安装并配置了 KnpMenuBundle。
安装
注意:RollerworksNavigationBundle 是 KnpMenuBundle 的补充,请确保您已安装并正确配置了 KnpMenuBundle。
推荐通过 Composer 安装 RollerworksNavigationBundle。
运行以下命令安装 rollerworks/navigation-bundle
包:
$ php composer.phar require rollerworks/navigation-bundle
现在,Composer 将自动下载所有必需的文件,并为您安装。之后,在内核中启用该插件
<?php // in AppKernel::registerBundles() $bundles = array( // ... new Rollerworks\Bundle\NavigationBundle\RollerworksNavigationBundle(), // ... );
用法
表达式
从 Symfony 2.4 开始,您可以通过使用 Symfony ExpressionLanguage 来使应用配置的一些部分更加动态。由于 RollerworksNavigationBundle 将导航定义注册为依赖注入容器中的服务,因此您还可以为“参数”配置参数使用表达式。
实际上,您可以使用表达式来处理导航翻译/路由和参数。
以 @
开头的参数值将被视为表达式,要标记值为“文本”,请使用双重 @
,例如 '@@your value'
,它将被转换为 '@your value'
。
注意:只有 第一个 前导 @@
被转换为单个 @
,其他 @
将保持不变。例如,'my@value' 不会转换为表达式。
使用专用服务处理菜单项/面包屑
如果您的导航是动态的,您也可以使用专用服务。该服务必须返回一个 Knp\Menu\ItemInterface
实例。
定义菜单
菜单在 rollerworks_navigation.menus
配置树中定义,您可以添加任意数量的菜单。
每个菜单都作为 rollerworks_navigation.menu.[menu-name]
在服务容器中注册,并使用 'menu-name' 标记为 KnpMenu 加载器。
rollerworks_navigation: menus: menu-name: template: ~ # optional template, used by the Menu builder items: item-name: # name of the item, eg. home, products, and such. label: ~ # Label of the menu-item, this will be translated with the translator_domain translator_domain: Menus # translator domain for the label route: { name: ~, parameters: { } } # The route.name can not be empty, parameters is optional # route can also be only a string (route name) uri: ~ # Alternatively you can use a URI instead of a route items: [] # Sub-level items, same as this example (unlimited depth nesting) # If your menu item is to dynamic you may also use a dedicated service. # The service must return a Knp\Menu\ItemInterface instance. service: id: ~ # service-id, can not be empty method: ~ # optional method to call on the service parameters: [] # Parameter to pass to the method (same as service container parameters, including Expression support) # Need full control? Speficy an expression get a Knp\Menu\ItemInterface instance # like: service('acme_customer.navigation').getMenu() expression: ~
注意:每个菜单项只能使用静态、服务或表达式之一。
使用服务或表达式时,子项必须由返回的 MenuItem 对象提供。
定义面包屑
面包屑在 rollerworks_navigation.breadcrumbs
配置树中定义,您可以定义任意数量的面包屑。
除了菜单之外,更深的面包屑引用其父级名称,父级可能会进一步引用另一个父级。
提示
将相关的面包屑(们)保存在它们自己的包中,并使用一个“根包”来引用。
使用Symfony Config组件的导入功能来从其他包导入配置文件。
在注册之前,最终结构会被规范化,因此不会在运行时执行复杂的构建或解析。
每个面包屑在服务容器中以rollerworks_navigation.breadcrumbs.[breadcrumb-name]
注册,并且根据“breadcrumb-name”标记为KnpMenu加载器。
注意
每个面包屑名称必须在整个应用程序中是唯一的。建议使用与service-id相同的约定。
例如,'homepage'可以命名为'acme_breadcrumbs.homepage'。
rollerworks_navigation: breadcrumbs: breadcrumb-name: # name of the breadcrumb item. Must be unique though out the application. parent: ~ # Optional parent breadcrumb to reference (by name) # Static configuration label: ~ # Label of the breadcrumb, this will be translated with the translator_domain translator_domain: Breadcrumbs # translator domain for the label route: { name: ~, parameters: { } } # The route.name can not be empty, parameters is optional # route can also be only a string (route name) uri: ~ # Alternatively you can use a URI instead of a route # If your breadcrumb is to dynamic you may also use a dedicated service. # The service must return a Knp\Menu\ItemInterface instance. service: id: ~ # service-id, can not be empty method: ~ # optional method to call on the service parameters: [] # Parameter to pass to the method (same as service container parameters, including Expression support) # Need full control? Speficy an expression get a Knp\Menu\ItemInterface instance # like: service('acme_customer.navigation').getBreadcrumb() expression: ~
版本控制
为了透明度和对发布周期的洞察,以及努力保持向后兼容性,RollerworksSearch尽可能地按照语义版本控制指南进行维护。
版本号将采用以下格式
<主版本>.<次版本>.<修订版>
并遵循以下指南
- 破坏向后兼容性会增加主版本(并重置次版本和修订版)
- 在不破坏向后兼容性的新功能会增加次版本(并重置修订版)
- 错误修复和杂项更改会增加修订版
有关SemVer的更多信息,请访问http://semver.org/。
许可证
本软件包的源代码受MIT许可证的约束,该许可证包含在源代码文件LICENSE中。