我尝试使用 KnpMenu 教程来创建菜单,并在 Symfony 中将其与引导程序一起使用。它在本地模式下完美运行,但是当我在我的服务器上尝试它时(都在开发模式下)它不起作用,我有这个错误:
在“robStormWelcomeBundle:Homepage:index.html.twig”中呈现模板(“类“robStorm\WelcomeBundle\Menu\Builder”不存在菜单构建器“robStormWelcomeBundle:Builder”。”)期间引发异常。500 内部服务器错误 - Twig_Error_Runtime 1 链接异常:InvalidArgumentException »
但是,我在本地或服务器上有完全相同的文件......
这是我的文件的内容:
在 app/config/config.yml 中:
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
twig:
form:
resources:
- "BraincraftedBootstrapBundle:Form:form_div_layout.html.twig"
knp_menu:
twig:
template: "BraincraftedBootstrapBundle:Menu:menu.html.twig"
在 src/robStorm/WelcomeBundle/Controller/HomepageController :
public function indexAction()
{
return $this->render('robStormWelcomeBundle:Homepage:index.html.twig');
}
在 src/robStorm/WelcomeBundle/Menu/builder.php :
<?php
namespace robStorm\WelcomeBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
use Knp\Menu\Matcher\Matcher;
use Knp\Menu\Matcher\Voter\UriVoter;
use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;
class Builder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$item = $menu->addChild('Accueil', array('route' => 'robStormWelcomeBundle_homepage'));
$menu->addChild('Combat', array('route' => 'robStormWelcomeBundle_homepage_combat'));
$menu->addChild('Boutique', array('uri' => '#'));
return $menu;
}
public function menuDroite(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Aide', array('uri' => '#'));
$menu->addChild('d1', array('attributes' => array('divider' => true)));
$dropdown = $menu->addChild('Mon compte');
$dropdown->addChild('Mon profil', array('uri' => '#'));
$dropdown->addChild('Mes messages', array('uri' => '#'));
$dropdown->addChild('d1', array('attributes' => array('divider' => true)));
$dropdown->addChild('Se déconnecter', array('uri' => '#'));
return $menu;
}
}
在 src/robStorm/WelcomeBundle/Ressources/config/routing.yml :
robStormWelcomeBundle_homepage:
pattern: /
defaults: { _controller: "robStormWelcomeBundle:Homepage:index" }
在 src/robStorm/WelcomeBundle/Ressources/views/layout.html.twig :
<div class="container">
{{ knp_menu_render('robStormWelcomeBundle:Builder:mainMenu', {'nav_type': 'navbar', 'currentAsLink': true}) }}
{{ knp_menu_render('robStormWelcomeBundle:Builder:menuDroite', {'nav_type': 'navbar', 'currentAsLink': true, 'pull': 'right'}) }}
</div>