Coder Social home page Coder Social logo

knpmenubundle's Introduction

KnpMenuBundle

The KnpMenuBundle integrates the KnpMenu PHP library with Symfony. This means easy-to-implement and feature-rich menus in your Symfony application!

Build Status Latest Stable Version Latest Unstable Version

What now?

Documentation! The documentation for this bundle is available in the docs directory of the bundle:

This bundle's job is to integrate a standalone PHP menu library called KnpMenu. You can learn a lot more about how this library works by reading that library's documentation.

Maintainers

Please read this post first.

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

  • @garak
  • @stof

Credits

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

knpmenubundle's People

Contributors

adou600 avatar adrienbrault avatar andreybolonin avatar bamarni avatar benjamindulau avatar chris53897 avatar chris8934 avatar dbu avatar derrabus avatar docteurklein avatar doncallisto avatar filhodanuvem avatar garak avatar herzult avatar javiereguiluz avatar jdreesen avatar jordisala1991 avatar loostro avatar lwagner avatar mbontemps avatar mhor avatar nek- avatar ornicar avatar peshi avatar redpanda avatar stof avatar uwej711 avatar vjousse avatar weaverryan avatar wouterj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knpmenubundle's Issues

Latest refactoring requires each menu to be defined as a service

With the latest refactoring and introduction of the ContainerAwareProvider for the menus you are forced to define all menues as a service when you want to use the KnpMenuBundle. Before I implemented my own provider that dynamically read menues from the database. I don't see an easy way to do that with the latest version of the bundle. Should I just use KnpMenu and skip the Bundle completly?

Easier way to define your menus

Hey guys!

So, currently - and also before the refactoring - you must define your menu as a service in order to reference it as a string when rendering it. With the addition of the need for a builder service, and then factory services for the menus, I think this is too hard.

One idea would be to allow the menu strings to take on different formats, something like the internal format of controller names:

  • main - would refer to a services tagged as menu, with alias name (as it works now)
  • AcmeMainBundle:Builder:main - would instantiate a Acme\MainBundle\Menu\Builder class, and call mainMenu() on it (or something with that idea).
  • main.builder:mainMenu - would use the main.builder service and call mainMenu on it

For the second part, that class would of course need to not have a constructor, but we'd document it extending ContainerAware (or maybe a base builder with the container + a few common services with PHP-doc'ed getters).

I don't want to confuse things (which this inevitably will to some degree), I just want things to be much easier. Needing to only create a single class and a single method is a big win I think.

Thoughts?

ERROR 1845

When trying to use the MenuBundle with the latest symfony, i get this error?!

Fatal error: Uncaught exception 'InvalidArgumentException' with message '[ERROR 1845] Element '{http://symfony.com/schema/dic/services}container': No matching global declaration available for the validation root. (in /Users/leon/Projects/diasend/vendor/bundles/Knplabs/Bundle/MenuBundle/Resources/config/provider.xml - line 3, column 0)'

anyone got a clue?

class KnplabsMenuBundle not found

Hi everyone,

I'm about to use the menu bundle, but I keep getting this error when I try to:

Fatal error: Class 'Knplabs\Bundle\MenuBundle\KnplabsMenuBundle' not found

I've put the bundle into my src-folder, so the autoload definition for the bundle looks like this:

...
'Knplabs'                        => __DIR__.'/../src',
...

And the AppKernel registration line:

...
new Knplabs\Bundle\MenuBundle\KnplabsMenuBundle(),
...

I did not experience similar problems with other bundles yet and I don't really know how to fix it, so maybe you can help me with that. I'm using Symfony PR11 right now.

Best regards,
Tim Bureck

Event Listeners

Hey folks,

for one of my applications I added the ability to modify the Menu via event listeners. In the Menus' constructor I dispatch a onMenuConfigure event and several bundles listen via services tagged with menu.listener and add their own children. Thanks to lazy loading and co this stuff only acts if the Menu is actually rendered in a template.

Is this interesting for the bundle itself to support it, without letting people write that listener/compilerpass/event stuff theirself? They only have to add the EventDispatcher in their Menu service constructor signature, add the one-liner to dispatch the onMenuConfigure event and create n listeners tagged with menu.listener.

If so, I would contribute that stuff.

Greetings, Pierre

Only expand active parent?

Are there any sugestions for something to only show the children of the active item ?
Or should that be handled by the class which extends Menu (and configures the items) ?

I don't know what the 'right' way to go is for this?

Error when trying to create a custom renderer

Hello,

I am trying to create a cutom renderer as shown in the documentation.... I get the following error :

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 1 passed to Application\FrontBundle\Menu\CustomRenderer::render() must implement interface Knp\Menu\ItemInterface, string given, called in C:\wamp\www\aletheiatrac\src\Application\FrontBundle\Menu\CustomRenderer.php on line 28 and defined in C:\wamp\www\aletheiatrac\src\Application\FrontBundle\Menu\CustomRenderer.php line 9") in "FrontBundle:Index:index.html.twig" at line 53.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:

I have the following configuration:

VIEW----------------------------------------------
{{ knp_menu_render('frontBundleMainMenu', {}, 'customRender') }}

MENUBUILDER----------------------------------
class MenuBuilder
{
private $factory;

/**
 * @param FactoryInterface $factory
 */
public function __construct(FactoryInterface $factory)
{
    $this->factory = $factory;
}

public function createFrontBundleMenu(Request $request)
{
    $menu = $this->factory->createItem('root');
    $menu->setCurrentUri($request->getRequestUri());

    $menu->addChild('Home', array('route' => 'main_menu', 'label' => 'Home', 'attributes' => array('icon' => '/bundles/front/images/buttons/home_64.png')));

    return $menu;
}

MY SERVICE ---------------------------------

services:
frontBundle_main.menu_builder:
class: Application\FrontBundle\Menu\MenuBuilder
arguments: ["@knp_menu.factory"]

frontBundle_main.menu.main:
    class: Knp\Menu\MenuItem # the service definition requires setting the class
    factory_service: frontBundle_main.menu_builder
    factory_method: createFrontBundleMenu
    arguments: ["@request"]
    scope: request # needed as we have the request as a dependency here
    tags:
        - { name: knp_menu.menu, alias: frontBundleMainMenu } # The alias is what is used to retrieve the menu

frontBundle_main.menu_renderer:
    class: Application\FrontBundle\Menu\CustomRenderer # the service definition requires setting the class
    arguments: [%kernel.charset%]
    tags:
        - { name: knp_menu.renderer, alias: cumRender } # The alias is what is used to retrieve the menu

CUSTOM RENDERER ------------------------------------------------

getDefaultOptions(), $options); ``` /** * Return an empty string if any of the following are true: * a) The menu has no children eligible to be displayed * b) The depth is 0 * c) This menu item has been explicitly set to hide its children */ /*if (!$item->hasChildren() || 0 === $options['depth'] || !$item->getDisplayChildren()) { return ''; }*/ return $this->render('FrontBundle:CustomRender:customRender.json.twig', array('attr' => $item->getAttributes(), 'item' => $item, 'options' => $options, 'level' => $item->getLevel()) )->getContent(); } ``` } I cant find the problem here. If someone can help me please :D Thanks.

Have an injected service to retrieve the current URI

#55 automatically sets the current URI from the request. but this will not work with subrequests or ESI. we should make this configurable.

does it make sense to inject a service in the dependency injection that gets the current uri and is used by Templating/Helper/MenuHelper.php ?

cc @uwej711

Menu item childs' html code

In "Resources/views/Menu/item.html.php", you should include sub-childs in the li markup.
It's the usual approach for sub lists.

As service: The menu “main” is not defined exception in rendering template

I'm using Symfony2 with the KnpMenuBundle installed as submodules and using the service configuration method.

When calling the page with the menu in the layout using:

{{ knp_menu_render('main') }}

I get the error:

An exception has been thrown during the rendering of a template ("The menu "main" is not defined.") in CCGlobalBundle::layout.html.twig

My services.yml file (is parsed in the load() method of the CCGlobalExtension.php bundle class) seems to be being called as intentional errors in it cause further code errors:

# src/CC/GlobalBundle/Resources/Config/services.yml
services:
cc_global.menu_builder:
    class: CC\GlobalBundle\Menu\MenuBuilder
    arguments: ["@knp_menu.factory"]

cc_global.menu.main:
    class: Knp\Menu\MenuItem # the service definition requires setting the class
    factory_service: cc_global.menu_builder
    factory_method: createMainMenu
    arguments: ["@request"]
    scope: request # needed as we have the request as a dependency here
    tags:
        - { name: knp_menu.menu, alias: main } 

And my main /app/config/config.yml file contains the knp_menu: directive:

twig: 
    template: knp_menu.html.twig
templating: false # if true, enables the helper for PHP templates
default_renderer: twig # The renderer to use, list is also available by default 

Does anyone know what might be causing this?

ReflectionException: Class Knp\Menu\ItemInterface does not exist

I just upgraded to the latest version of KnpMenuBundle. It's throwing a ReflectionException: Class Knp\Menu\ItemInterface does not exist from line 19 of Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddTemplatePathPass.php. I tried emptying the cache and reinstalling the vendors, but that didn't fix the problem. What's going on?

Outdated documentation ?!

Hello,

First, thank for your bundle !
Next, I'm new on Symfony2 so I'm not familiar with depency injection.
I use the PR6.

In your documentation, you add in your app/config/config.yml :
menu.twig:

This return me an error : There is no extension able to load the configuration for "menu".

Indeed in Knplabs/MenuBundle/DependencyInjection/KnplabsMenuExtension.php , getAlias() return 'knplabs_menu'.

When I write in my app/config/config.yml :
knplabs_menu:
twig: true

It works...
Documentation is outdated or am I doing something wrong?

There is also a problem in my Extension who's extends Extension who's implements ExtensionInterface.
I changed
public function menuLoad($config, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(DIR.'/../Resources/config'));
$loader->load('menu.xml');
}
by
public function load(array $configs, ContainerBuilder $configuration)
{
$loader = new XmlFileLoader($configuration, new FileLocator(DIR.'/../Resources/config'));
$loader->load('menu.xml');
}

Now it works for me... but I don't know if it's the best practice...
:)

menu is not defined

Hi,
after this commit:

20563d4 by @stof

I got error "The menu "blog_admin" is not defined."
When I revert changes in Resources/config/menu.xml everything works fine.
any idea why ?

knplabs Namespace?

What about putting the MenuBundle into its own Bundle namespace (according to best practices from the sf2 manual). E.g. Bundle\knplabs\MenuBundle? I'd prefer that!

Breadcrumbs

Hi,

I've looked around but couldn't find any way to easily render a breadcrumb, so I developed my own BreadcrumbRenderer. Should you think it's useful to others and within the wanted scope of this project, let me know and I'll push it.

Licence

Can you include a proper Licence file ?

Thanks

Add access permissions for showing decisions

Goal

  • Some users have different permissions to different modules
  • Different modules could provide different menu items like "Create new course", "Edit my courses" and etc.
  • Menu item "Course" / "Create new course" should be shown only to users having ROLE_CREATE_COURSE role assigned

Possible solution

  • Add dependency to SecurityContext

  • Modify function signatures to fit the following possible usage:

    $menu = new MenuItem('Courses');
    $menu->addChild('Create new', $router->generate('create_course'), 'ROLE_CREATE_COURSE');
    $menu->addChild('Edit own', $router->generate('edit_own_courses'), 'ROLE_EDIT_OWN_COURSES');
    $mainMenu->addChild($menu);

The function "menu" does not exist

I hope this is the right place to post this question, I am new to the Symfony2 and KnpLabs Communities.

I get this exception The function "menu" does not exist in AsvymMainBundle:Default:index.html.twig at line 6

This only happens when I add the twig tag {{ menu('main') }} to my view
With out this tag the page renders ok.

I have installed Symfony2 Beta 1 and Symfony profiler shows the KnplabsMenuBundle as an Active Bundle under CONFIG

I followed the document 03-Twig-Integration.markdown in the Resources/doc folder

Log from exception page is:
DEBUG [2011-05-21 16:46:28] event.DEBUG: Notified event "onCoreController" to listener "JMS\SecurityExtraBundle\Controller\ControllerListener".
DEBUG [2011-05-21 16:46:28] event.DEBUG: Notified event "onCoreException" to listener "Symfony\Bundle\FrameworkBundle\Profiler\ProfilerListener".

ERROR [2011-05-21 16:46:28] request.ERROR: Twig_Error_Syntax: The function "menu" does not exist in "AsvymMainBundle:Default:index.html.twig" at line 6 (uncaught exception)

DEBUG [2011-05-21 16:46:28] event.DEBUG: Notified event "onCoreRequest" to listener "Symfony\Bundle\FrameworkBundle\RequestListener".
DEBUG [2011-05-21 16:46:28] event.DEBUG: Notified event "onCoreRequest" to listener "Symfony\Bundle\FrameworkBundle\Profiler\ProfilerListener".

I see this What now? In the documentation?
You will need 5 steps to get to the point where you can just type in your Twig template:
{{ menu('main') }}

Create a Menu class:
did this in src/Asvym/MainBundle/Menu/MainMenu.php
created class MainMenu extends Menu ...

Declare a Menu service
create a menu.xml to declare your menu.main service
in src/Asvym/MainBundle/Resources/config/menu.xml

Load your Menu service in the Dependency Injection Extension
in Asvym\MainBundle\DependencyInjection\AsvymMainExtension.php added
$loader->load('menu.xml');

Enable the Dependency Injection for your bundle
Not shure what this part is

Render your menu with Twig
This is where I get error using {{ menu('main') }}

Thanks for the help
Mike

[Doc] Missing suggestion about determination active item

Bundle user should know how he can detect active item.

Sometimes there are complex cases, for example:
there are "meets" and they are be past or future.

meets
|-past (MeetsBundle:List:past)
|-future (MeetsBundle:List:future)

Also possible view one meet (MeetsBundle:View:view). And depends on current date and date of meet we should highlight relevant branch: meets-past or meets-future.

homepage without trailing slash

Since Symfony2 no longer redirects app_dev.php to app_dev.php/ the menu bundle doesn't know it's current uri is the homepage without the trailing /. Not sure if this is a Symfony2 or a MenuBundle issue.

How to translate / change this text ⌂

Hi,
I'm newbie in Sf2 world,
Could anyone tell me how to change / translate this text (⌂) in breadcrumb title ?
I need to translate / change it to "Home" or "Dashboard" label.

Regards.

Setting current item for dynamic pages

This is a fairly general setup, but I will explain it with my current specific example. I am creating a real estate web site and there is a section for Agents. The link to the agents page (/agents) is in the menu, but the agents themselves (which are pulled from a database) are not. When visiting /agents the correct item is current, but when visit /agents/debi, the /agents link is not current but I would like it to be. Is there already a way to enable this kind of functionality, besides a mess of if's, sub_str's, etc in the menu factory?

If not, it seems the easiest way to implement this kind of behavior would be to enable certain menu items to match to the beginning of the URI, rather than the whole thing. IE: /agents would match /agents/debi as well as /agents.

A usable alternative would be a way to set the current URI in the controller (probably via a service), which would be done in the special exception that I am on one of these special pages.

If you feel it would be a worthwhile to implement one of these options, I would be happy to create a PR, but I am not sure where to start.

[Doc] Menu from a dynamic source

The documentation on how to build a menu from a tree could use some more information on what type of object should be passed as $node. Maybe an example with Doctrine where a database menu object is retrieved and then passed to the MenuFactory? This would leave the choice of database to the user but give more insight on how to build a menu from a dynamic source.

Injected Request '_route' attribute is empty

It seems my Request object is missing the '_route' attribute when injected to a menu builder with some custom components (factory and renderer). However, the '_controller' attribute is correctly there. I also have a second builder, which uses the built-in factory as well as the renderer and the '_route' attribute is set there. Here's the relevant part of my code.

Services:

    <service id="gilden_aire.menu.archive" factory-service="gilden_aire.menu.builder" factory-method="tableMenu" class="Gilden\Bundle\AireBundle\Menu\IconMenuItem">
        <argument type="service" id="gilden_aire.menu.factory" />
        <tag name="knp_menu.menu" alias="archive" />
    </service>

    <service id="gilden_aire.menu.builder" class="Gilden\Bundle\AireBundle\Menu\ArchiveBuilder">
        <call method="setContainer">
            <argument type="service" id="service_container" />
        </call>
    </service>

    <service id="gilden_aire.menu.factory" class="Gilden\Bundle\AireBundle\Menu\IconAwareFactory">
        <argument type="service" id="router" />
    </service>

    <service id="gilden_aire.menu.renderer" class="Gilden\Bundle\AireBundle\Menu\ListIconRenderer">
        <argument>%kernel.charset%</argument>
        <tag name="knp_menu.renderer" alias="archive" />
    </service>

Here's the builder

<?php

class ArchiveBuilder extends ContainerAware
{
    public function tableMenu(IconAwareFactory $factory)
    {
        $menu = $factory->createItem('root');

        $request = $this->container->get('request');
        $route = $request->attributes->get('_route');
        var_dump($route); // RETURNS NULL

        /* snip */
    }

    /* snip */
}

My menu is rendered by using ´{{ knp_menu_render('archive', {}, 'archive') }}´

What am I missing here?

MenuItem autoload erreur

Bonjour,

J'ai installé votre MenuBundle dans une Symfony2 PR12 et j'obtiens l'erreur suivante :
Class 'Knplabs\Bundle\MenuBundle\MenuItem' not found in .../Symfony/src/Knplabs/Bunble/MenuBundle/Menu.php on line 16
J'ai essayé de le mettre dans Symfony/vendor/ mais ça ne change rien.

Pouvez-vous m'aider ?

Merci beaucoup
Arnaud BECKER

Menu undefined when use as a service

I am new to Symfony2 and this undefined issue has plagued me for hours. I have followed the KnpMenuBundle and the KnpMenu documents to build my main navigation menu which is called out in my base.html.twig template with {{ knp_menu_render('main') }}. I am using Symfony 2.0.6 and have the latest of the KnpMenu and bundle.

My menu builder from my SiteBundle is as follows (I changed all my routes during troubleshooting to see if that was causing menu to be undefined):

<?php
// src/NEGL/SiteBundle/Menu/MenuBuilder.php

namespace NEGL\SiteBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class MenuBuilder
{
    private $factory;

    /**
     * @param FactoryInterface $factory
     */
    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createMainMenu(Request $request)
    {
        $menu = $this->factory->createItem('root');
        $menu->setCurrentUri($request->getRequestUri());

        $menu->addChild('Home', array('uri' => '#homepage'));
        $menu->addChild('Events', array('uri' => '#events'));
        $menu->addChild('Community', array('uri' => '#community'));
        $menu->addChild('Files', array('uri' => '#files'));
        $menu->addChild('Partners', array('uri' => '#partners'));
        $menu->addChild('Support', array('uri' => '#support'));
        $menu->addChild('Servers', array('uri' => '#servers'));
        $menu->addChild('FAQ', array('uri' => '#faq'));
        $menu->addChild('About', array('uri' => '#about'));
        $menu->addChild('Jobs', array('uri' => '#job_openings'));


        return $menu;
    }

here is the service:

#  src/NEGL/SiteBundle/Resources/Config/services.yml
services:
    negl_site.menu_builder:
        class: NEGL\SiteBundle\Menu\MenuBuilder
        arguments: ["@knp_menu.factory"]

    negl_site.menu.main:
        class: Knp\Menu\MenuItem # the service definition requires setting the class
        factory_service: negl_site.menu_builder
        factory_method: createMainMenu
        arguments: ["@request"]
        scope: request # needed as we have the request as a dependency here
        tags:
            - { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu

in my app/config/config.yml:

knp_menu:
    twig: true

I cannot seem to figure out what is the issue. I am sorry if this type of issue should have been posted to the Symfony2-User Group. Thank you for your help in advance. It is probably something I am just overlooking.

Consistency of templating helpers

Hey guys-

The new Twig integration uses a menu "tag" when declaring menus, which allows for a Twig extension so that you can easily render the menus. The "PHP" templating helper requires more setup, but returns a MenuHelper object that you can work with in the view.

Which method does everyone prefer? I do like the tag method - you can reference the menu by name and render it (thought this could also be done without a tag - by just referencing the full service name). The Twig method doesn't allow you to make mutations to your menu in the view, but I think that's the "best practice" to go towards.

Which method does everyone prefer? With the Twig method, common rendering options (i.e. depth) would need to be added.

Thanks!

Unable to pass (Request $request, Router $router) to MenuBundle as a service

I followed the instructions on MenuBundle doc folder 02-Integrate-With-Symfony.markdown
changing only vendor and bundle name and I get this error:


Catchable fatal error: Argument 1 passed to Devsign\MenuServiceBundle\Menu\MainMenu::__construct() must be an instance of Symfony\Component\HttpFoundation\Request, none given, called in D:\Web\www\1103.temaenergy.it\app\AppKernel.php on line 20 and defined in D:\Web\www\1103.temaenergy.it\src\Devsign\MenuServiceBundle\Menu\MainMenu.php on line 14


I used, as in the documentation, the following menu.xml to configure the service:


<parameters>
    <parameter key="menu.main.class">Devsign\MenuServiceBundle\MainMenu</parameter>
</parameters>

<services>
    <service id="menu.main" class="%menu.main.class%" scope="request">
        <tag name="menu" alias="main" />
        <argument type="service" id="request" />
        <argument type="service" id="router" />
    </service>
</services>

I think the problem is in the argument tags but don't know how to solve the problem.
When i call $this->get('menu.main'); from a Controller all the logic works but the arguments
$request and $router are not passed in MainMenu __construct()

Could you help me?

Improve the configuration

  • The configuration should allow disabling unused built-in providers to allow improving performances as described in #76.
  • The template should be configurable when using the TwigRenderer, by keeping it organized (so having the template config under the twig item)

Extending MenuItem not working correctly?

Hi,

it seems that when extending the MenuItem class and overwriting the renderLink() menu has no effect. It just looks like the renderLink() method is never called.
The docs say to overwrite this method to enable custom rendering but it does not work.

Rendering inconsistency

There is currently 2 ways to render a menu in a template (examples use Twig ones):

  • menu('main', 3) uses the template
  • menu_get('main').render(3)|raw uses the renderer configured in the MenuItem object.

I find this a bit weird. What about creating a TemplatingRenderer which would allow to be consistent: the rendering would always use the configured renderer. I can work on it if the KnpTeam agree that this should be changed.

Security integration

Hi!

Is i possible to somehow get some items of the menu out depending on the current user access rights?

Call to undefined method Knp\Bundle\MenuBundle\DependencyInjection\KnpMenuExtension::processConfiguration()

i found this, i dont know if its an error but for me, it was a nasty error :)

use Symfony\Component\Config\Definition\Processor;

class KnpMenuExtension extends Extension{
public function load(array $configs, ContainerBuilder $container)
{
..
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
..
}

instead of
$config = $this>processConfiguration($configuration, $configs);

Routes with parameters

Hi,

I implemented a menu with a custom menuBuilder as suggested in the docs like so:

public function createMainMenu()
{
    $menu = $this->factory->createItem('root');
    $menu->setCurrentUri($this->request->getRequestUri())
         ->setAttributes(array('id' => 'menu-main', 'class' => 'menu'));

    $menu->addChild('Home', array('route' => 'daily_home'));
    $menu->addChild('Foo', array('route' => 'daily_foo'));
    $menu->addChild('Bar', array('route' => 'daily_bar'));

    return $menu;
}

and the route 'daily_foo' expects a parameter {page} wich is set to 1 by default:

<route id="daily_foo" pattern="/foo/{page}">
    <default key="_controller">DailySiteBundle:Foo:bar</default>
    <default key="page">1</default>
    <requirement key="page">\d+</requirement>
</route>

Now, when the menu is rendered the css class 'current' is correctily added to the

  • tag, but only when invoked via the URI '/foo'. When invoked via '/foo/2' i.e. it is not. Am I missing something in the config?

    Thanks in advance for taking the time and best regards.

  • [twig branch] Circular reference detected for service templating

    In the twig branch, we use twig as templating engine. But the following happens:

    • Controller ->render(…)
    • Container ->get ('templating')
    • Container ->get ('twig')
    • Container ->get ('templating.helper.menu')
    • the MenuHelper needs the templating service, so… Container ->get ('templating')

    => circular reference.

    MenuFactory

    Hello,
    this line
    ...
    public function createFromArray(array $data)
    {
    $class = isset($data['class']) ? $data['class'] : 'MenuItem';
    ...

    'MenuItem' is missing namespace? or i use it bad?

    [Solved] fatal: https://github.com/knplabs/KnpMenu.git/info/refs not found

    I have got errors when I run 'php bin/vendors install'. Once the script is going to install Knp Bundles i get:

    Installing/Updating KnpMenu
    Cloning into /var/www/myproject/vendor/KnpMenu...
    fatal: https://github.com/knplabs/KnpMenu.git/info/refs not found: did you run git update-server-info on the server?
    cd: 1: can't cd to /var/www/myproject/vendor/KnpMenu

    UPDATE: Answer

    => Update your urls from knplabs/KnpMenuBundle.git to KnpLabs/KnpMenuBundle.git (case change)

    Overwriting knp_menu.html.twig in the 'normal' way

    At the moment, this file ships with KnpMenu, not KnpMenuBundle, and thus is not overwritable by using the documented method to overwrite a template. Overwriting the renderer should not be necessary for this step.

    I should be able to provide a app/Resources/KnpMenuBundle/views/knp_menu.html.twig file to overwrite the template.

    How can I get current selected menu item from twig template?

    I include knp menu in template with code like

    {{ knp_menu_render('Bundle:Builder:mainMenu',{ 'currentClass': 'active','template': 'Bundle:Menu:main.html.twig' }) }}
    

    I have 1 level menu and a lot of the pages on site, most of them are attached to some "Big" section on site within menu builder with code like

            switch($this->container->get('request')->attributes->get('_route')) {
                case "route1":
                case "route2":
                case "route3":
                    $menu['mainmenuMedia']->setCurrent(true);
                    break;
                case "route4":
                    $menu['mainmenuNews']->setCurrent(true);
                    break;
    

    I want to customize main layout based on selected route.

    My question is - how should I do it, so I will not need to duplicate top menu selection code. I see a couple solution

    1. render {{ knp_menu_render('Bundle:Builder:mainMenu',{ 'currentClass': 'active','template': 'Bundle:Menu:another_template.html.twig' }) }} and put needed customizations in another_template. Right now I need to customize only logo, so it may work as a solution, but if I will need to add more customization - it would create too much load on server - build menu and render it each time.
    2. move section selection code from menu builder to new service, which will return current top section selected based on route, create global variable in twig. It seems to be the most "right" way.
    3. use some knp_menu feature, which I dont know :)
    4. duplicate code and create simple twig macros, which will do needed customizations based on selected route. It seems to be most stupid way, but its also most fast from development side and most easy for server, so right now I choose this one :)

    Thanks for answers if any ;)

    Support for the ol list tag

    For now as far as I can see the only list type supported is an unordered < ul >, I know that I can easily override template for ordered lists, but I think It should be supported, by the menu components itself?

    Renaming the repository to follow best practices

    The best practices recommend to use the bundle logical name as github repository name to avoid collision for people forking them (forking both FOSUserBundle and SonataUserBundle before the renaming would have lead to have only one repo on your account, but a messed one for instance).
    So the repository should be renamed to KnplabsMenuBundle (without changing anything in it except the url in the doc). This has been done just now by FOS and Liip, and will be done for FOQ repos soon, and probably other ones as we are asking people to follow the best practice. The sooner it is done the better to avoid changing the repo url after the stable release.

    I open the issue here but it applies also for other Knplabs repos.

    Improving Templating Helper

    I'd like to improve the Templating/Helper/MenuHelper.php a little bit (to be more consistently with the Twig extension):

    • load menus via services tagged as menu (e.g. <tag name="menu" alias="main" />)
    • lazy load / inject those services (see Twig/MenuExtension.php)
    • render them via $view['menu']->get('main')->render()

    Any further ideas? Does this break the current API too much?

    Link attributes not working

    Hi,

    it seems that setLinkAttributes() does not work. No matter what attributes are passed none of them is added to the generated link.

    Security and credentials

    Does the MenuBundle already implements "Security and credentials" like the ioMenuPlugin (i.e. $menu->addChild('manage account')->requiresAuth(true);) ?

    Or, there is other (good) way to do this?

    (Sorry, if this isn't content for here...)

    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.