如何用 XML 写这个?
# src/Acme/MainBundle/Resources/config/services.yml
services:
acme_main.menu_builder:
class: Acme\MainBundle\Menu\MenuBuilder
arguments: ["@knp_menu.factory"]
acme_main.menu.main:
class: Knp\Menu\MenuItem # the service definition requires setting the class
factory_service: acme_main.menu_builder
factory_method: createMainMenu
arguments: ["@request"]
scope: request # needed as we have the request as a dependency here
tags:
- { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu
我已经尝试过了,但出现下一个错误:xml:
<!-- Knp Menu -->
<service id="acme.menu_builder" class="Acme\FrontendBundle\Menu\MenuBuilder">
<argument type="service" id="knp_menu.factory" />
<argument type="service" id="security.context" />
</service>
<service id="acme.menu.main" class="Acme\Menu\MenuItem" scope="request">
<argument type="service" id="acme_menu.menu_builder" />
<argument type="service" id="request" />
<tag name="knp_menu.menu" alias="main" method="createMainMenu" />
</service>
错误:
ErrorException: Catchable Fatal Error: Argument 2 passed to Knp\Menu\MenuItem::__construct() must implement interface Knp\Menu\FactoryInterface, instance of Symfony\Component\HttpFoundation\Request given