knpMenuBundle symfony 4

问题描述 投票:1回答:1

我尝试在symfony 4中使用knpMenuBundle

我渲染{{knp_menu_render('App:MenuBuilder:menuTags')}}

class在src / App \ Menu \ MenuBuilder中

得到

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?").

其次我试着用它作为服务 -

{{ knp_menu_render('App\Menu\Builder:menuTags') }}

不工作......

我可以将此自动注册服务注入其他控制器。

我在包装中读到 -

KnpMenuBundle v2.2.1
require:
symfony/framework-bundle: ~2.7|~3.0 | ^4.0

所以它应该工作 - 在官方symfony文档中有关symfony 4的任何信息

https://symfony.com/doc/master/bundles/KnpMenuBundle/menu_service.html

我认为删除APpBundle是一种愚蠢的方式......

知道如何使用MenuBuilder吗?

symfony symfony4 knpmenubundle
1个回答
1
投票

你不能使用这个“{{knp_menu_render('App \ Menu \ Builder:menuTags')}}”进行服务。使用您创建的服务的别名。

使用Symfony 4,您需要将菜单用作服务。

试试看。

{{ knp_menu_render ('main') }}
© www.soinside.com 2019 - 2024. All rights reserved.