trunda/smf-menu
Composer 安装命令:
composer require trunda/smf-menu
包简介
Integrates KnpMenu to Nette framework
README 文档
README
SmfMenu is just integration library for KnpMenu.
Installation
Easiest way to install the addon is via composer:
composer install trunda/smf-menu
and then register the extension in your config.neon:
extensions: - Smf\Menu\Config\Extension
What is KnpMenu?
The KnpMenu library provides object oriented menus for PHP 5.3. With following API.
<?php use Knp\Menu\MenuFactory; use Knp\Menu\Renderer\ListRenderer; $factory = new MenuFactory(); $menu = $factory->createItem('My menu'); $menu->addChild('Home', array('uri' => '/')); $menu->addChild('Comments', array('uri' => '#comments')); $menu->addChild('Symfony2', array('uri' => 'http://symfony-reloaded.org/')); $menu->addChild('Coming soon'); $renderer = new ListRenderer(); echo $renderer->render($menu);
The above menu would render the following HTML:
<ul> <li class="first"> <a href="/">Home</a> </li> <li class="current"> <a href="#comments">Comments</a> </li> <li> <a href="http://symfony-reloaded.org/">Symfony2</a> </li> <li class="last"> <span>Coming soon</span> </li> </ul>
This way you can finally avoid writing an ugly template to show the selected item, the first and last items, submenus, ...
Usage
Extension adds factory for the menu control, so in presenter is usable like this:
abstract class BasePresenter extends Presenter { /** @var Menu\Control\Factory */ private $menuFactory; public function injectMenuFactory(Menu\Control\Factory $factory) { $this->menuFactory = $factory; } protected function createComponentMenu() { $menu = $this->menuFactory->createControl(); $root = $menu->getRoot(); $root->addChild('catalog', array( 'label' => 'Katalog', 'icon' => 'book' )); $root['catalog']->addChild('categories', array( 'label' => 'Categories', 'link' => 'Category:list', 'icon' => 'table', )); $root['catalog']->addChild('new', array( 'label' => 'Product', 'link' => 'Product:list', 'icon' => 'gift', )); // .... return $menu; } // ... }
and then in your template you can use obligate control macro:
{control menu}
Renderers
You can register as many renderers as you want. Some default renderers are registered by defaul:
list => Smf\Menu\Renderer\ListRenderer
bootstrapNav => Smf\Menu\Renderer\BootstrapNavRenderer
You can use them in template
{control menu:list} {control menu:bootstrapNav}
Registration of new renderer is as easy as adding new service to your config with tag menuRenderer:
services: myRenderer: class: My\Super\Renderer tags: menuRenderer: mySuperRenderer
And then you can use it:
{control menu:mySuperRenderer}
Credits
Credits goes to original authors of KnpMenu library as to authors of KnpMenuBundle.
trunda/smf-menu 适用场景与选型建议
trunda/smf-menu 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.45k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2013 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「tree」 「nette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trunda/smf-menu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trunda/smf-menu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trunda/smf-menu 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
jsTree widget for yii2
A Symfony extension to get active class base on current bundle/controller/action
Doctrine2 behavior traits - slowhop fork
Nette Framework adapter for I18n package
Build forms from schema
A fast and dynamic Merkle tree implementation
统计信息
- 总下载量: 10.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-30