Download the PHP package rnr1721/le7-menu-builder without Composer
On this page you can find all versions of the php package rnr1721/le7-menu-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package le7-menu-builder
le7-menu-builder
HTML menu builder for le7 PHP MVC framework or any PHP 8 project
The PHP Menu Manager is a flexible and customizable class that allows you to create, manage, and render menus in your PHP applications. It provides functionality to add, remove, and modify menu items, as well as rendering the menu in various formats.
Key Features:
- Create and manage hierarchical menus with unlimited levels of depth.
- Manage many different menus in one instance with different renderers
- Manage attributes and rels of links in menu
- Add, remove, and modify menu items with ease.
- Customize menu rendering by providing your own rendering engine or using the default one.
- Support for caching to improve performance when rendering menus.
- Easily import and export menu items from an external data source.
- Add 'variables' to links URLs that will be replaced with some text (templates)
The Menu Manager class is designed to be simple to use and extend. It uses an array-based data structure to represent menus and provides methods to manipulate and render the menus.
Install
Testing
Basic usage
Multiple different menus in one instance of MenuBuilder
You can build and render different menus in one instance. When you create instance of MenuBuilder, it will create default menu named 'default'. But you can easy create another and make it active. Example:
'Variables' in links (Templated links)
In some cases, you may need to store variables in links, not full URL
Now, if you export your menu, {url} will be replaced to https://example.com IMPORTANT: it will not work with raw links added by addRawItem method
Raw links
This project use this implementation of PSR LinkInterface: https://github.com/rnr1721/le7-links This implementation of both PSR LinkInterface and UriInterface, but contain own methods, such as render, getAnchor, withAnchor etc...
Renderer options
Any MenuRenderer have own set of settings as array. You can see default settings and change them when render. Example for bootstrap renderer:
Of course, you can change this options:
IMPORTANT: not necessary to set all options, you can change only that you need to change. Also, you can not change data type of option, it will call exception. Every renderer can have own list of options or dont have them.
Cache options
You can cache the menu render result.
Renderers
These renderers are available now, but you can write own renderer that implements MenuRendererInterface. Now out-of-the-box available this renderers:
- BootstrapMenuRenderer same as HtmlMenuRenderer but bootstrap cpecyfic
- HtmlMenuRenderer renders HTML menu
- ArrayMenuRenderer renders array menu
- JsonMenuRenderer renders JSON menu
MenuRendererInterface:
You can customize the rendering of the menu by providing your own rendering engine or modifying the default one. Additionally, caching can be enabled to improve performance when rendering menus.
Import and export menu items configuration
You can import and export menu items configuration.
Example: