Symfony KnpMenuBundle 显示错误 [MenuBuilder 即服务]

Symfony KnpMenuBundle showing error [MenuBuilder As a Service]

我正在使用 sumfony 3.3.10,我已经安装了一个新的 symfony 项目,并且我使用这个命令添加了 knpMenuBundle,

composer require knplabs/knp-menu-bundle "^2.0"

现在我完全按照这里提到的一切进行操作 http://symfony.com/doc/master/bundles/KnpMenuBundle/menu_builder_service.html

并在 default/index.html.twig 文件中添加了这一行 {{ knp_menu_render('main') }}

现在,当我执行该项目时,它向我显示此错误,

[InvalidArgumentException]


Menu builder services must be public but "app.menu_builder" is a private service.

config.yml

knp_menu:
        # use "twig: false" to disable the Twig extension and the TwigRenderer
        twig:
            template: KnpMenuBundle::menu.html.twig
        #  if true, enables the helper   for PHP templates
        templating: false
        # the renderer to use, list is also available by default
        default_renderer: twig

MenuBuilder.php

    <?php
namespace AppBundle\Menu;

use Knp\Menu\FactoryInterface;

    class MenuBuilder
{
    private $factory;

    /**
     * @param FactoryInterface $factory
     *
     * Add any other dependency you need
     */
    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createMainMenu(array $options)
     {
        $menu = $this->factory->createItem('root');

        $menu->addChild('Home', array('route' => 'homepage'));
        // ... add more children

        return $menu;
     }
 }

services.yml

app.menu_builder:
            class: AppBundle\Menu\MenuBuilder
            arguments: ["@knp_menu.factory"]
            tags:
                - { name: knp_menu.menu_builder, method: createMainMenu, alias: main } # The alias is what is used to retrieve the menu

我该如何解决。任何帮助深表感谢。谢谢

我将 public: true 添加到 services.php 中的 app.menu_builder 服务,

app.menu_builder:
        class: AppBundle\Menu\MenuBuilder
        public: true
        arguments: ["@knp_menu.factory"]
        tags:
            - { name: knp_menu.menu_builder, method: createMainMenu, alias: main } # The alias is what is used to retrieve the menu

现在一切正常。

参考:https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private