定制 kebir/menu-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kebir/menu-generator

Composer 安装命令:

composer require kebir/menu-generator

包简介

Simple Menu Generator

README 文档

README

Build Status

Menu Generator

Installations

Install through composer:

{
    require: {
        "kebir/menu-generator": "dev-master"
    }
}

Usage

<?php

//Given this list of menus
$menus = [
    ["id" => 1, "name" => "Menu 1", "url" => "test.com", "parent_id" => 3],
    ["id" => 2, "name" => "Menu 2", "url" => "test.com", "parent_id" => 0],
    ["id" => 3, "name" => "Menu 3", "url" => "test.com", "parent_id" => 0],
    ["id" => 4, "name" => "Menu 4", "url" => "test.com", "parent_id" => 2],
    ["id" => 5, "name" => "Menu 5", "url" => "test.com", "parent_id" => 3],
    ["id" => 6, "name" => "Menu 6", "url" => "test.com", "parent_id" => 1],
];

//Let's build a hierarchical menus list
$builder = new Kebir\MenuGenerator\Builder();
$menus_generated = $builder->build($menus);

//Check the output
foreach ($menus as $menu) {
    echo $menu->getName() . "-" . $menu->getUrl()."\n";
    foreach ($menu->getElements() as $submenu) {
        echo "--- ".$submenu->getName()."\n";
    }
}
/** output
    Menu 2 - test.com
        --- Menu 4
    Menu 3 - test.com
        --- Menu 1
        --- Menu 5
*/

If you want to display the menu, the package provides a HtmlListRenderer class that will display the menus using html <ul> and <li> tags. The class requires an instance of Kebir\MenuGenerator\Selector\Selector which is responsible of detecting if a menu should considered as selected.

<?php

$current_url = 'http://test.com/page1';
$simple_selector = new Kebir\MenuGenerator\Selector\SimpleUrlSelector($current_url);
$renderer = new Kebir\MenuGenerator\Renderer\HtmlListRenderer($simple_selector);
echo "<ul>";
foreach ($menus as $menu) {
    $renderer->render($menu);
}
echo "</ul>";

Laravel Users

The package includes a Service Provider and a Facade for the Renderer. Edit the app/config/app.php:

<?php

  //Add the service provider
  'Kebir\MenuGenerator\MenuGeneratorServiceProvider'
  ...
  //add the facade alias
  'MenuRenderer'    => 'Kebir\MenuGenerator\Facades\Renderer'

To use it, simply call the following in your blade template for example:

{{ MenuRender::render($menu) }}

Menu Selection

To mark a menu as selected, you can use the Kebir\MenuGenerator\Selector\SimpleUrlSelector class when creating the menu renderer.

For laravel users, the service provider is configured to include the Kebir\MenuGenerator\Selector\LaravelSelector instead. This will allow you, in the config file provided, to define which entry in the menu should be selected when a page is reached.

This is very useful when the current page is not in the menu but is related to another url which is in the menu. Here is an example of usage for the config/config.php file

<?php
return array(
   //To link /users/1/edit to another url /users in the menu.
   'linked_urls' => array(
        '/users/1/edit' => '/users'
    ),
    
    //To link an action to an url
    'linked_actions' => array(
        'UsersController@edit' => '/users'
    ),
    
    //To link a route to an url
    'linked_routes' => array(
        'user_edit_path' => '/users'
    )
);

kebir/menu-generator 适用场景与选型建议

kebir/menu-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 kebir/menu-generator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-02