我遵循了本教程:
https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md#installation
并遇到以下错误:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "page_show" as such route does not exist.") in /var/www/bundles/src/Acme/DemoBundle/Resources/views/Default/index.html.twig at line 4.
我在这里是否缺少将某些内容传递给控制器的步骤?
从链接:
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class Builder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Home', array('route' => 'homepage'));
$menu->addChild('About Me', array(
'route' => 'page_show',
'routeParameters' => array('id' => 42)
));
// ... add more children
return $menu;
}
}
要实际呈现菜单,只需在任何 Twig 模板中的任何位置执行以下操作:
{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu') }}