Bonjour,

j'essai de suivre le totu officiel du KNPMenuBundle, chapitre "creating menu as services":
https://symfony.com/doc/current/bund...u_service.html

mon template twig ne reconnait pas un service:
An exception has been thrown during the rendering of a template ("You have requested a non-existent service "app.main_menu".").
#service.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
app.menu_builder:
        class: AppBundle\Menu\FactoryInterface\MenuBuilder
        arguments:
            - "@knp_menu.factory"
app.main_menu:
        class: Knp\Menu\MenuItem
        factory: 
            - "@app.menu_builder"
            - createMainMenu
        arguments: ["@request_stack"]
        tags:
            - { name: knp_menu.menu, alias: main }
#template.html.twig
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
{# empty Twig template #}
{% extends "::base.html.twig" %}
{% block body %}
            {{ knp_menu_render('main') }}
{% endblock %}
#MenuBuilder.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace AppBundle\Menu\FactoryInterface;
 
use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
 
class MenuBuilder {
    private $factory;
    public function __construct(FactoryInterface $factory) {
        $this->factory = $factory;
    }
    public function createMainMenu(RequestStack $requestStack) {
        $menu = $this->factory->createItem('root');
        $menu->addChild('Home', array('route' => 'homepage'));
        return $menu;
    }
}