PHPackages                             pieceofcake2/menu\_builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pieceofcake2/menu\_builder

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

pieceofcake2/menu\_builder
==========================

A dynamic menu building helper for CakePHP 2.x

v2.0.4(7mo ago)00MITPHPPHP ^8.0CI passing

Since Oct 6Pushed 7mo agoCompare

[ Source](https://github.com/pieceofcake2/menu_builder)[ Packagist](https://packagist.org/packages/pieceofcake2/menu_builder)[ RSS](/packages/pieceofcake2-menu-builder/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

MenuBuilder Helper
==================

[](#menubuilder-helper)

[![GitHub License](https://camo.githubusercontent.com/5050527acaf15f835f72979288f2b846145856cbc4c97c49cfe82f88cdb5147f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70696563656f6663616b65322f6d656e755f6275696c6465723f6c6162656c3d4c6963656e7365)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/b5d016da3c3c197065523ac5accebdd3f1f45568973d76b3a1a4655e6e1361b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70696563656f6663616b65322f6d656e755f6275696c6465723f6c6162656c3d5061636b6167697374)](https://packagist.org/packages/pieceofcake2/menu_builder)[![PHP](https://camo.githubusercontent.com/814aaf975b9877cd5fceef4e3f68c21c0551189ac4d51b54435f0ed7ee7108fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f6d656e755f6275696c6465722f7068703f6c6f676f3d706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d504850266c6162656c436f6c6f723d25323337373742423426636f6c6f723d253233464646464646)](https://camo.githubusercontent.com/814aaf975b9877cd5fceef4e3f68c21c0551189ac4d51b54435f0ed7ee7108fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f6d656e755f6275696c6465722f7068703f6c6f676f3d706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d504850266c6162656c436f6c6f723d25323337373742423426636f6c6f723d253233464646464646)[![CakePHP](https://camo.githubusercontent.com/8e45518d782aa331e1f07d54afd0d86d78e803e3d81afbc653c14b741923f734/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f6d656e755f6275696c6465722f70696563656f6663616b65322f63616b657068703f6c6f676f3d63616b65706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d43616b65504850266c6162656c436f6c6f723d25323344333343343326636f6c6f723d253233464646464646)](https://camo.githubusercontent.com/8e45518d782aa331e1f07d54afd0d86d78e803e3d81afbc653c14b741923f734/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f6d656e755f6275696c6465722f70696563656f6663616b65322f63616b657068703f6c6f676f3d63616b65706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d43616b65504850266c6162656c436f6c6f723d25323344333343343326636f6c6f723d253233464646464646)[![CI](https://camo.githubusercontent.com/e33b30ce126338b9a0d0353997b4588f4e5e0344802b61d8910bdb9bbe4e4e1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70696563656f6663616b65322f6d656e755f6275696c6465722f43492e796d6c3f6c6162656c3d4349)](https://github.com/pieceofcake2/menu_builder/actions/workflows/CI.yml)[![Codecov](https://camo.githubusercontent.com/b33251ce3064ffcbff66a5a4319c106e427b8dbc17f7589909c05e878be63b4c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f70696563656f6663616b65322f6d656e755f6275696c6465723f6c6162656c3d436f766572616765)](https://codecov.io/gh/pieceofcake2/menu_builder)

**This is forked for CakePHP2.**

A dynamic menu building helper for CakePHP

Background
----------

[](#background)

This is a menu building helper with lot of customization options. Check out the **Usage** section.

Now it supports menus built with [ACL Menu Component](http://mark-story.com/posts/view/acl-menu-component) by [Mark Story](http://mark-story.com/)

Features
--------

[](#features)

- Generate menu based on current user type/group/permission/level (Can be used with Auth, Authsome, etc Components)
- Provide various useful CSS class
- Multi-level menu support
- Supports [ACL Menu Component](http://mark-story.com/posts/view/acl-menu-component) by [Mark Story](http://mark-story.com/)
- CakePHP Unit Test (100% Code coverage)

Requirements
------------

[](#requirements)

- CakePHP 2.10+
- PHP 8.0+

Installation
------------

[](#installation)

Add the plugin to your project's:

```
composer require pieceofcake2/menu_builder
```

Because this plugin has the type `cakephp-plugin` set in its own `composer.json`, Composer will install it inside your `/Plugins` directory, rather than in the usual vendors file. It is recommended that you add `/Plugins/MenuBuilder` to your .gitignore file. (Why? [read this](http://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md).)

### Enable plugin

[](#enable-plugin)

In 2.x you need to enable the plugin in your `app/Config/bootstrap.php` file:

```
CakePlugin::load('MenuBuilder');
```

If you are already using `CakePlugin::loadAll();`, then this is not necessary.

Usage
-----

[](#usage)

### Minimal Setup

[](#minimal-setup)

Load the Plugin by modifying your app/Config/bootstrap.php

```
...
CakePlugin::load('MenuBuilder');
```

or

```
...
CakePlugin::loadAll();
```

To use this helper add the following to your AppController:

```
...
var $helpers = [..., 'MenuBuilder.MenuBuilder'];

function beforeFilter() {
    ...
    // Define your menu
    $menu = [
        'main-menu' => [
            [
                'title' => 'Home',
                'url' => ['controller' => 'pages', 'action' => 'home'],
            ],
            [
                'title' => 'About Us',
                'url' => '/pages/about-us',
            ],
        ],
        'left-menu' => [
            [
                'title' => 'Item 1',
                'url' => ['controller' => 'items', 'action' => 'view', 1],
                'children' => [
                    [
                        'title' => 'Item 3',
                        'url' => ['controller' => 'items', 'action' => 'view', 3],
                    ],
                    [
                        'title' => 'Item 4',
                        'url' => ['controller' => 'items', 'action' => 'view', 4],
                    ],
                ]
            ],
            [
                'title' => 'Item 2',
                'url' => ['controller' => 'items', 'action' => 'view', 2],
            ],
        ],
    ];

    // For default settings name must be menu
    $this->set(compact('menu'));
    ...
}
```

Now to build your `main-menu` use the following code in the View:

```
echo $this->MenuBuilder->build('main-menu');
```

You'll get the following output in the Home (/pages/home) page:

```

    Home
    About Us

```

And to build your `left-menu` use the following code in the View:

```
