tereta / application-menu
The menu package for the tereta/application framework.It stores per-site menu trees as JSON in the database, exposes them as a block for the layout and manages them with the menu:edit, menu:show and menu:remove console commands.
Requires
- php: >=8.2
- psr/log: ^3.0
- tereta/application: @dev
- tereta/console: @dev
- tereta/dbal: @dev
- tereta/orm: @dev
- tereta/route: @dev
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
π English | Π ΡΡΡΠΊΠΈΠΉ | Π£ΠΊΡΠ°ΡΠ½ΡΡΠΊΠ°
Menu package for the tereta/application framework.
It keeps the menus of each site in the database and shows them on the pages of the site.
Requirements
PHP 8.2+, tereta/application.
Installation
composer require tereta/application-menu
After installation, run the database migration of the application, so the menu table is created.
Menu tree
A menu is a list of items. Each item has a label and a link.
An item can have its own list of items in menu, so menus can be nested:
[
{"label": "Home", "link": "/"},
{"label": "Catalog", "link": "/catalog", "menu": [
{"label": "Phones", "link": "/catalog/phones"},
{"label": "Laptops", "link": "/catalog/laptops"}
]},
{"label": "Contacts", "link": "/contacts", "icon": "contacts.svg"}
]
Manage menus
Menus are managed from the console. Each menu belongs to a site and has its own name.
Create a menu or replace an existing one:
php bin/console.php menu:edit base main '[{"label":"Home","link":"/"}]'
Here base is the site and main is the menu name.
Show all menus of a site:
php bin/console.php menu:show base
Show one menu:
php bin/console.php menu:show base main
Remove a menu:
php bin/console.php menu:remove base main
Menus on the page
The package gives three menus to the page: main, footer and footer:middle.
In a template they are available in $meta['blocks']:
<ul>
<?php $include('blocks/menu', $meta['blocks']['main']) ?>
</ul>
Each site shows its own menus. If a menu is not created yet, the page gets an empty list.
License
Apache License 2.0