2017 © Pedro Peláez
 

cakephp-plugin menu

A KnpMenu seasoned menu plugin for CakePHP.

image

icings/menu

A KnpMenu seasoned menu plugin for CakePHP.

  • Sunday, June 24, 2018
  • by ndm2
  • Repository
  • 2 Watchers
  • 4 Stars
  • 1,352 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 12 Versions
  • 35 % Grown

The README.md

Menu

Build Status ![Coverage Status][ico-coverage] Latest Version ![Software License][ico-license], (*1)

A KnpMenu seasoned plugin that assists with creating menus for your CakePHP applications., (*2)

Requirements

  • CakePHP 4.0+ (use the 3.x branch of this plugin if you need CakePHP 3 compatibility)
  • KnpMenu 3.0+

Installation

  1. Use Composer to add the menu plugin to your project:, (*3)

    $ composer require icings/menu
    
  2. Make sure that you are loading the plugin in your bootstrap, either run:, (*4)

    $ bin/cake plugin load Icings/Menu
    

    or add the following call to your Application class' bootstrap() method in the src/Application.php file:, (*5)

    $this->addPlugin('Icings/Menu');
    
  3. Load the helper in your AppView class' initialize() method, located in the src/View/AppView.php file:, (*6)

    $this->loadHelper('Icings/Menu.Menu');
    

Usage

Detailed usage documentation can be found in the docs folder. For those that are familiar with CakePHP and KnpMenu, here's two examples for a quick start., (*7)

Via the Menu helper

Build and render the menu via the helpers create() and render() methods:, (*8)

$menu = $this->Menu->create('main');
$menu->addChild('Home', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'home']]);
$menu->addChild('About', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'about']]);

$menu->addChild('Services', ['uri' => '#']);
$menu['Services']->addChild('Research', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'research']]);
$menu['Services']->addChild('Security', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'security']]);

$menu->addChild('Contact', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'contact']]);

echo $this->Menu->render();

In the default setup, this would generate the following HTML:, (*9)

<ul>
    <li>
        <a href="/pages/display/home">Home</a>
    </li>
    <li>
        <a href="/pages/display/about">About</a>
    </li>
    <li class="has-dropdown">
        <a href="#">Services</a>
        <ul class="dropdown">
            <li>
                <a href="/pages/display/research">Research</a>
            </li>
            <li>
                <a href="/pages/display/security">Security</a>
            </li>
        </ul>
    </li>
    <li>
        <a href="/pages/display/contact">Contact</a>
    </li>
</ul>

Using the library directly

Aside from using the menu helper and its various configuration possibilities, it's also possible to manually utilize the library provided by this plugin, optionally combining things with the KnpMenu library:, (*10)

use Icings\Menu\Integration\PerItemVotersExtension;
use Icings\Menu\Integration\RoutingExtension;
use Icings\Menu\Integration\TemplaterExtension;
use Icings\Menu\Matcher\Matcher;
use Icings\Menu\Matcher\Voter\UrlVoter;
use Icings\Menu\MenuFactory;
use Icings\Menu\Renderer\StringTemplateRenderer;

$factory = new MenuFactory();
$factory->addExtension(new RoutingExtension());
$factory->addExtension(new PerItemVotersExtension());
$factory->addExtension(new TemplaterExtension());

$menu = $factory->createItem('main');
$menu->addChild('Home', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'home']]);
$menu->addChild('About', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'about']]);
$menu->addChild('Services', ['uri' => '#']);
$menu['Services']->addChild('Research', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'research']]);
$menu['Services']->addChild('Security', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'security']]);
$menu->addChild('Contact', ['uri' => ['controller' => 'Pages', 'action' => 'display', 'contact']]);

$matcher = new Matcher();
$matcher->addVoter(new UrlVoter($this->request));

$renderer = new StringTemplateRenderer($matcher);
echo $renderer->render($menu);

Issues

Please use the issue tracker to report problems., (*11)

The Versions

24/06 2018

1.x-dev

1.9999999.9999999.9999999-dev

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

24/06 2018

1.0.3

1.0.3.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

21/06 2018

dev-master

9999999-dev

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

21/06 2018

2.0.2

2.0.2.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

20/06 2018

2.0.1

2.0.1.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

07/05 2018

1.0.2

1.0.2.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

06/05 2018

2.0.0

2.0.0.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

05/05 2018

2.0.x-dev

2.0.9999999.9999999-dev

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

02/10 2017

1.0.1

1.0.1.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

21/05 2017

1.0.0

1.0.0.0

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

14/05 2017

1.0.0-beta2

1.0.0.0-beta2

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu

12/05 2017

1.0.0-beta1

1.0.0.0-beta1

A KnpMenu seasoned menu plugin for CakePHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp menu knp-menu