承接 knplabs/knp-menu 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

knplabs/knp-menu

最新稳定版本:v3.8.0

Composer 安装命令:

composer require knplabs/knp-menu

包简介

An object oriented menu library

关键字:

README 文档

README

The KnpMenu library provides object-oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone.

Build Status Latest Stable Version Latest Unstable Version Gitter chat

Installation

KnpMenu uses Composer, please check out the composer website for more information.

The simple following command will install knp-menu into your project. It also adds a new entry in your composer.json and update the composer.lock as well.

composer require knplabs/knp-menu

KnpMenu follows the PSR-4 convention names for its classes, which means you can easily integrate knp-menu classes loading in your own autoloader.

Getting Started

<?php

// Include dependencies installed with composer
require 'vendor/autoload.php';

use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;

$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
$menu->addChild('Home', ['uri' => '/']);
$menu->addChild('Comments', ['uri' => '#comments']);
$menu->addChild('Symfony', ['uri' => 'http://symfony.com/']);
$menu->addChild('Happy Awesome Developers');

$renderer = new ListRenderer(new \Knp\Menu\Matcher\Matcher());
echo $renderer->render($menu);

The above menu would render the following HTML:

<ul>
  <li class="first">
    <a href="/">Home</a>
  </li>
  <li class="current">
    <a href="#comments">Comments</a>
  </li>
  <li>
    <a href="http://symfony.com/">Symfony</a>
  </li>
  <li class="last">
    <span>Happy Awesome Developers</span>
  </li>
</ul>

This way you can finally avoid writing an ugly template to show the selected item, the first and last items, submenus, ...

The bulk of the documentation can be found in the doc directory.

What now?

Follow the tutorial in doc/01-Basic-Menus.md and doc/02-Twig-Integration.md to discover how KnpMenu will rock your world!

Find all available documentation at doc/.

Maintainers

This library is maintained by the following people (alphabetically sorted) :

Credits

This bundle was originally ported from ioMenuPlugin, a menu plugin for symfony1. It has since been developed by KnpLabs and the Symfony community.

统计信息

  • 总下载量: 53.84M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1419
  • 点击次数: 2
  • 依赖项目数: 332
  • 推荐数: 7

GitHub 信息

  • Stars: 1399
  • Watchers: 58
  • Forks: 191
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04