2017 © Pedro Peláez
 

project menu-builder

Menu builder

image

roboc/menu-builder

Menu builder

  • Wednesday, August 3, 2016
  • by roboc
  • Repository
  • 1 Watchers
  • 2 Stars
  • 124 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Menu builder

Easy way to build navigation menus, (*1)

Scrutinizer Code Quality Build Status, (*2)

Example usage

Create Menu

$menu = new Menu('main-menu');

Add menu items

$menu->item('Home')->to('/');

Use badges

$menu->item('Inbox')->to('inbox')->badge(5);

Create submenu

$menu->item('Reports')
    ->subMenu( function ( Menu $menu )
    {
        $menu->item('Summary')->to('/reports/summary');
        $menu->item('Detailed')->to('/reports/detailed');
    } );

Render menu

Using JSON renderer

$json = ( new \Roboc\Menu\Renderer\JsonRenderer )->render( $menu );

Output:, (*3)

[
    {
        "title": "Home",
        "link": "\/"
    },
    {
        "title": "Inbox",
        "link": "inbox",
        "badge": {
            "value": 5,
            "attributes": []
        }
    },
    {
        "title": "Reports",
        "children": [
            {
                "title": "Summary",
                "link": "\/reports\/summary"
            },
            {
                "title": "Detailed",
                "link": "\/reports\/detailed"
            }
        ]
    }
]

Using simple HTML renderer

$html = ( new \Roboc\Menu\Renderer\HtmlRenderer )->render( $menu );

Output:, (*4)

<ul id="main-menu">
    <li><a href="/">Home</a></li>
    <li><a href="/inbox">Inbox <span class="badge">5</span></a></li>
    <li>Reports
        <ul>
            <li><a href="/reports/summary">Summary</a></li>
            <li><a href="/reports/detailed">Detailed</a></li>
        </ul>
    </li>
</ul>

Other

You can create your own menu renderer or build menu output direclty in your code, (*5)

The Versions

03/08 2016

dev-master

9999999-dev

Menu builder

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Roberts Jurkjans

menu builder