Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Knp Menu Laravel Package

knplabs/knp-menu

View on GitHub
Deep Wiki
Context7

Matcher to determine the current page

Basics

A Matcher is capable of determining if a menu item is the menu entry for the current page, or an ancestor thereof. The default matcher implementation uses the voter pattern.

Here is an example of how to use the matcher:

use Knp\Menu\Matcher\Matcher;

$itemMatcher = new Matcher([new UriVoter(str_replace('/index.php', '', $_SERVER['REQUEST_URI']))]);

To use the Matcher you have to pass it to your renderer. For the ListRenderer, this looks like:

use Knp\Menu\Renderer\ListRenderer;

new ListRenderer($itemMatcher);

Available voters

KnpMenu provides some voters for standard cases:

  • RegexVoter: checks if the request matches a regular expression you pass to the voter
  • RouteVoter: uses a Symfony request to check if the current route is the same as the route of the menu item
  • UriVoter: compare the URI of the menu item with the URI passed to the voter
  • CallbackVoter: allows matching based on a callback set as match_callback under the extras option of the menu item

Create your own voters

You can create your own voters by implementing VoterInterface.

use Knp\Menu\Matcher\Voter\VoterInterface;

class MyAwesomeVoter implements VoterInterface
{
    // Your code
}

Note: You can also write your own matcher that implements the MatcherInterface, if you need something different from the voter approach.

If you use the KnpMenuBundle, the RouteVoter is automatically loaded.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk