KNP菜单Symfony 3.4

时间:2018-01-08 08:06:59

标签: php symfony knpmenubundle

我很难让它工作,我收到以下错误:

  

无法找到模板“KnpMenuBundle :: menu.html.twig”(查看:D:\ Server \ htdocs \ symfonudem \ app / Resources / views,D:\ Server \ htdocs \ symfonudem \ vendor \ symfony \ symfony \ SRC \的Symfony \桥\枝条/资源/视图/表格)。

以下是我的Builder类代码。

<?php
namespace AppBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class Builder
{
  use ContainerAwareTrait;

  public function mainMenu(FactoryInterface $factory, array $options)
  {
    $menu = $factory->createItem('root');

        $menu->addChild('Home', ['route' =>  'homepage']);


        return $menu;
  }
}

 ?>

以下是base.html.twig

的代码
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}
        <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
        {% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
    </head>
    <body>
      {{ knp_menu_render('AppBundle:Builder:mainMenu') }}

        {% block body %}{% endblock %}
        {% block javascripts %}
        <!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        {% endblock %}
    </body>
</html>

您的建议将非常受欢迎。

2 个答案:

答案 0 :(得分:0)

尝试添加

templating:
        engines: ['twig']

到配置文件的框架部分

答案 1 :(得分:0)

您可以按如下方式说明菜单构建器的完整路径:

{{ knp_menu_render('AppBundle:Builder:institutionMenu', {'allow_safe_labels': true, 'currentClass': 'active' })|raw }}