Giter Site home page Giter Site logo

knpmenu's Introduction

KnpMenu

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

Build Status Latest Stable Version Latest Unstable Version Gitter chat

Installation

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

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

$ composer require knplabs/knp-menu

KnpMenu follows the PSR-0 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', array('uri' => '/'));
$menu->addChild('Comments', array('uri' => '#comments'));
$menu->addChild('Symfony2', array('uri' => 'http://symfony-reloaded.org/'));
$menu->addChild('Coming soon');

$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-reloaded.org/">Symfony2</a>
  </li>
  <li class="last">
    <span>Coming soon</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.markdown and doc/02-Twig-Integration.markdown to discover how KnpMenu will rock your world!

Credits

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

knpmenu's People

Contributors

bamarni avatar bchoquet-heliopsis avatar canni avatar cvschaefer avatar dbu avatar docteurklein avatar geertdd avatar h4cc avatar hason avatar havvg avatar jfsimon avatar jmontoyaa avatar korstiaan avatar krymen avatar leokolln avatar mbontemps avatar n1c01a5 avatar naderman avatar nek- avatar peterdavehello avatar pzaloznyi avatar sagikazarmark avatar sebastianljunggren avatar smurfy avatar stof avatar tarjei avatar weaverryan avatar wouterj avatar xabbuh avatar yethee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.