承接 delatbabel/nestedmenus 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

delatbabel/nestedmenus

Composer 安装命令:

composer require delatbabel/nestedmenus

包简介

A Laravel 5 package for nested menus with database storage.

README 文档

README

Database storage of nested menus, including rendering

Based On

Comes with

  • Migration for the menus table
  • Menu Model (that extends Baum/Node so you can use all the handy methods from this excellent nested set implementation)
  • Seed for building the menu nodes, one for each type of menu

Installation

Add these lines to your composer.json file:

    "require": {
        "delatbabel/nestedmenus": "~1.0"
    },

Once that is done, run the composer update command:

    composer update

Alternatively just run this command:

    composer require delatbabel/nestedmenus

Register Service Provider

After composer update completes, add this line to your config/app.php file in the 'providers' array:

    Delatbabel\NestedMenus\NestedMenusServiceProvider::class

Publish the Migrations

Publish the migrations

    php artisan vendor:publish

Run the migration

    php artisan migrate

Ensure the categories types are set correctly in the seeder file. You can initialise this to whatever you like.

Run the Seeders

Run the seed (this will create the base menu structure as defined in the seeder)

    php artisan db:seed

You may prefer to build your own MenusTableSeeder class based on the code in MenusTableBaseSeeder to seed your own initial set of menus.

Usage

This class relies on the behind-the-scenes capabilities of Baum. For details on the use of that see the README on github or the Baum web site

Creating the Menu Structure

See the MenusTableBaseSeeder for an example of how to build the menu structure in the database. You can in fact just extend this seeder to create your own seeder, just overriding the function getNodes() to provide the menu structure to seed into the database.

Menu editors and the such like are still to be done.

The important parts of the database structure look like this when completed:

+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+
| id | parent_id | lft  | rgt  | depth | slug           | name           | url                     | route |
+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+
|  1 |      NULL |    1 |   14 |     0 | example-menu   | Example Menu   |                         | NULL  |
|  2 |         1 |    2 |    3 |     1 | example-list   | Example List   | sysadmin/example        | NULL  |
|  3 |         1 |    4 |    5 |     1 | example-create | Example Create | sysadmin/example/create | NULL  |
|  4 |         1 |    6 |   13 |     1 | example-edit   | Example Edit   | sysadmin/example/edit   | NULL  |
|  5 |         4 |    7 |    8 |     2 | example-edit-1 | Example Edit 1 | sysadmin/example/edit/1 | NULL  |
|  6 |         4 |    9 |   10 |     2 | example-edit-2 | Example Edit 2 | sysadmin/example/edit/2 | NULL  |
|  7 |         4 |   11 |   12 |     2 | example-edit-3 | Example Edit 3 | sysadmin/example/edit/3 | NULL  |
+----+-----------+------+------+-------+----------------|----------------+-------------------------+-------+

Note that at the moment the renderers available only support a 2 level menu structure. Level 0 is the heading. At level 1 are the various options, and at level 2 are the sub-options for each option.

See the Baum functions for more detail on creating and manipulating this structure.

Loading the Menu Structure

The menu structure can be loaded from the database using any normal Eloquent Model code, for example:

    $menu = \Delatbabel\NestedMenus\Models\Menu::where('slug', '=', 'example-menu')->first();

Note that you only need to load the top level of the menu in order to be able to render the entire menu.

Rendering the Menu Structure

See the ShowMenu class under src/Console/Commands for the details on how to do this. It's really simple:

    $renderer = new LavarySidebarRenderer();
    $rendered = $renderer->renderToHtml($menu);

Rendering to different menu structures requires different renderer classes. I will build more of these over time.

Placing the rendered menu on a view is as simple as this:

    return View::make("dashboard.example")
        ->with('sidebar_menu', $sidebar_menu);

TODO

Integrate additional menu front end creators. There are a few out there. I have decided to allow for integration of both of these:

Lavary Menu

Completed a LavarySidebarRenderer class. I had to extend the Lavary menu classes in order to do this, so instead of their main repo use the VCS mentioned in the composer.json in this package. I have submitted a PR to the Lavary repo for this change. See PR #100.

Need to have separate renderer classes for the other menu types (header menus, pulldown menus, etc).

Vespakoen Menu

TBD

Architecture

Rationale

I want to be able to create AdminLTE based menus, which look like this:

<!-- Sidebar Menu -->
<ul class="sidebar-menu">
    <li class="header">HEADER</li>
    <!-- Optionally, you can add icons to the links -->
    <li class="active"><a href="#"><i class='fa fa-link'></i> <span>Link</span></a></li>
    <li><a href="#"><i class='fa fa-link'></i> <span>Another Link</span></a></li>
    <li class="treeview">
        <a href="#"><i class='fa fa-link'></i> <span>Multilevel</span> <i class="fa fa-angle-left pull-right"></i></a>
        <ul class="treeview-menu">
            <li><a href="#">Link in level 2</a></li>
            <li><a href="#">Link in level 2</a></li>
        </ul>
    </li>
</ul><!-- /.sidebar-menu -->

I want to be able to create them dynamically rather than embed them in the view files.

I want to be able to store the menu structure in a database table so that it can be modified at run time or without having to change any code.

Imports

After using Baum successfully for my Nested Categories package, It seemed the obvious choice for heirarchical storage of the menu structure.

The only thing that remained is the creation of the views. I figured that there were a few options:

  • Use a Laravel / Blade template to create the menu and import it into a page as a section.
  • Use a package to create the menu structure and format it for display.

I found many packages on line to format the menu structure for display, but the two that I settled on were these:

delatbabel/nestedmenus 适用场景与选型建议

delatbabel/nestedmenus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 delatbabel/nestedmenus 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-03