I am new to Symfony, and trying to follow the instructions at https://symfony.com/doc/current/KnpMenuBundle/index.html to set up a navigation menu the "easy" way. It says to "first create a new class in the Menu directory of one of your bundles." I thought bundles were things that I install with composer. I don't know that I have any bundles of my own, as such. The docs go on to say that an example builder class would look like
// src/Menu/Builder.php [ <-- comment in the original ]
namespace App\Menu;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
// [etc]
final class Builder
{
public function mainMenu(FactoryInterface $factory, array $options): ItemInterface
{
$menu = $factory->createItem('root');
$menu->addChild('Home', ['route' => 'homepage']);
// [etc]
// create another menu item
$menu->addChild('About Me', ['route' => 'about']);
// you can also add sub levels to your menus as follows
$menu['About Me']->addChild('Edit profile', ['route' => 'edit_profile']);
// ... add more children
return $menu;
}
}
so I put this file in src/Menu/Builder.php
and try to render it, as shown in the documentation, in my base.html.twig template by saying {{ knp_menu_render('App:Builder:mainMenu') }}
. The result is a RuntimeError:
An exception has been thrown during the rendering of a template ("Bundle "App" does not exist or it is not enabled. Maybe you forgot to add it in the "registerBundles()" method of your "App\Kernel.php" file?").
I'm quite sure the KnpMenuBundle is registered in my config/bundles.php, but I don't know how to solve the above error about the "Bundle 'App'"
(I've also tried registering it as a service, per the instructions, but that didn't work either. I didn't save the error information produced by that effort, but I will repeat the steps and post it if anyone thinks it would be useful.)
I could use some help understanding where I'm going wrong. Thanks.