dereuromark / cakephp-menu
Composable menu builder and renderer for CakePHP
Package info
github.com/dereuromark/cakephp-menu
Type:cakephp-plugin
pkg:composer/dereuromark/cakephp-menu
Requires
- php: >=8.2
- cakephp/cakephp: ^5.3
Requires (Dev)
- php-collective/code-sniffer: dev-master
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5 || ^12.1 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-02 21:52:12 UTC
README
Composable menu builder and renderer for CakePHP applications.
This branch is for CakePHP 5.3+. See the version map for details.
Features:
- nested menu trees with string and Cake-style array URLs
- active-state matching with alternate routes, named routes, and fuzzy matching
- helper-managed named menus and breadcrumb integration
- extensible resolvers and renderers for app-specific rules
Installation
composer require dereuromark/cakephp-menu
Load the plugin:
bin/cake plugin load CakeMenu
Load the helper in your AppView:
use Cake\View\View; class AppView extends View { public function initialize(): void { parent::initialize(); $this->loadHelper('CakeMenu.Menu'); } }
Quick Start
use CakeMenu\Menu; $menu = Menu::create(['class' => 'nav']); $menu->addItem('Dashboard', ['controller' => 'Dashboard', 'action' => 'index']); $account = $menu->addItem('Account', '#', [ 'attributes' => ['class' => 'nav-item'], ]); $account->getSubMenu()->setAttributes(['class' => 'submenu']); $account->add($menu->newItem('Profile', ['controller' => 'Users', 'action' => 'profile'])); $account->add($menu->newItem('Logout', ['controller' => 'Users', 'action' => 'logout'])); echo $this->Menu->render($menu);
Documentation
Full documentation lives at https://dereuromark.github.io/cakephp-menu/.
Demo
https://sandbox.dereuromark.de/menu-sandbox
0.2 API changes
Menu callbacks accept Closure; use $service->method(...) for method references.
Sort with CakeMenu\SortDirection::Asc or Desc. Authentication data accepts
CakeMenu\Resolver\AuthState or its backed string; unknown strings throw.
The helper uses attributes when building a menu. Build options (attributes,
overwrite, cache, rebuild) do not become render defaults. Registration closures
receive the menu and helper. renderBreadcrumbs($menu, $options) uses BreadcrumbRenderer;
use populateBreadcrumbs() before calling Cake's Breadcrumbs->render() yourself.
PermissionResolver calls can($identity, $permission, $item). RegexResolver takes a
server request and supports dataKey and maxDepth options. MenuInterface exposes
collect() and item-class accessors; setItemClass() propagates to new submenus.
See the upgrade guide for migration examples.