lukesnowden/menu 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lukesnowden/menu

最新稳定版本:1.4.1

Composer 安装命令:

composer require lukesnowden/menu

包简介

Effortless menu building for Laravel 4

README 文档

README

http://luke.sno.wden.co.uk/menu for more information and for feature requests.

Usage

Very simple method of building menus from database data (id, parent id), service provider register methods for application modules and much more.

Standalone

use LukeSnowden\Menu\Menu;
include __DIR__ . '/vendor/autoload.php';

Example 1

<?php
Menu::addItem( array( 'text' => 'Home', 'URL' => '/', 'reference' => '0' ) );
echo Menu::render();
?>

##Example 2 - Nesting Children

<?php
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) );
echo Menu::render();
?>

Example 3 - Multiple Menus

<?php
Menu::addItem( array( 'text' => 'Services', 'URL' => '/services/', 'reference' => '1', 'parent' => '0' ) )->toMenu( 'main' );
echo Menu::render( 'main' );
?>

Auto classes

I have added in some of the most used and required classes for styling menus

.first-item {}
.last-item {}
.current-root {}
.current-parent {}
.current-ancestor {}
.has-children {}

Output

<?php
Menu::addItem( array( 'text' => 'Home', 'URL' => '/menu-test-2/public/', 'reference' => '1', 'class' => 'home-icon', 'weight' => 0 ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Services', 'URL' => '/menu-test-2/public/services/', 'reference' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Development', 'URL' => '/menu-test-2/public/services/development/', 'reference' => '3', 'parent' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Design', 'URL' => '/menu-test-2/public/services/design/', 'reference' => '4', 'parent' => '2', 'weight' => 0 ) )->toMenu( 'main' );
echo Menu::render( 'main' );
?>
<ul class="nav-main">
    <li class="home-icon current first-item container node-1">
        <a href="/menu-test-2/public/">Home</a>
    </li>
    <li class=" has-children last-item container node-1">
        <a href="/menu-test-2/public/services/">Services</a>
        <ul>
            <li class=" first-item nav-node node-2">
                <a href="/menu-test-2/public/services/design/">Design</a>
            </li>
            <li class=" last-item nav-node node-2">
                <a href="/menu-test-2/public/services/development/">Development</a>
            </li>
        </ul>
    </li>
</ul>

Custom attributes

$name = false, $attributes = array(), $htmlTag = 'ul'

echo Menu::render( 'main', array( 'class' => 'nav nav-pills nav-stacked', 'role' => 'tablist' ), 'nav' );

Custom Layout Render

You may want to change the output layout (demo render class included)

Menu::addItem( array( 'text' => 'Home', 'URL' => '/menu-test-2/public/', 'reference' => '1', 'class' => 'home-icon', 'weight' => 0 ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Services', 'URL' => '/menu-test-2/public/services/', 'reference' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Development', 'URL' => '/menu-test-2/public/services/development/', 'reference' => '3', 'parent' => '2' ) )->toMenu( 'main' );
Menu::addItem( array( 'text' => 'Design', 'URL' => '/menu-test-2/public/services/design/', 'reference' => '4', 'parent' => '2', 'weight' => 0 ) )->toMenu( 'main' );

Menu::setMenuType( 'horizontal', 'main', 'LukeSnowden\Menu\Styles' );
echo Menu::render( 'main' );

Use with third party menu UI through L4 Model

(Please note this is just a general summary of how it would work if you had 2 tables (and models) for navigations and navigation items with a standard hasMany() relationship)

<?php
$navigation = Navigation::with( 'navigationItems' )->where( 'navigation_slug', '=', 'main' )->get();
foreach( $navigation->navigationItems as $item )
{
    Menu::addItem( array( 'text' => , $item->name 'URL' => $item->url, 'reference' => $item->id, 'parent' => $item->parent_id, 'weight' => $item->order ) )->toMenu( $navigation->navigation_slug );
}
echo Menu::render( $navigation->navigation_slug );
?>

Laravel Install

Add the following to you applications composer.json file

composer require lukesnowden/menu:dev-master

add the following to your /app/config/app.php's provider array.

'LukeSnowden\Menu\MenuServiceProvider'

add the following to your /app/config/app.php's aliases array.

'Menu'      => 'LukeSnowden\Menu\Facades\Menu'

and finally back to your terminal and run

php composer.phar dump-autoload

统计信息

  • 总下载量: 2.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固