Giter Club home page Giter Club logo

knpmenu's Introduction

KnpMenu

KnpMenu类库可以为PHP 5.3提供面向对象的菜。
在Symfony2中,最初用于 KnpMenuBundle 不过现在可以单独使用了

Build Status Latest Stable Version Latest Unstable Version

<?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();
echo $renderer->render($menu);

上面的代码将会生成如下的 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>

通过这样的方式,你终于不必为了显示“第一项”,“最后一项”,“子菜单”而编写一个丑陋的模版了

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

Installation

KnpMenu 不提供自动加载器 but follow the PSR-0 convention. 你可以对这个类库使用任何兼容的加载器, for instance the Symfony2 ClassLoader component. 假设你签出的类库在 vendor/KnpMenu下面, 它应该这样配置:

<?php
$loader->registerNamespaces(array(
    'Knp\Menu' => __DIR__.'/vendor/KnpMenu/src'
    // ...
));

What now?

Follow the tutorial in doc/01-Basics-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

stof avatar bamarni avatar jfsimon avatar weaverryan avatar mslagee avatar havvg avatar adrienbrault avatar herzult avatar cvschaefer avatar canni avatar yethee avatar jmontoyaa avatar docteurklein avatar korstiaan avatar krymen avatar leokolln avatar mbontemps avatar naderman avatar tarjei avatar smurfy avatar

Watchers

James Cloos avatar  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.