Q
Q
Quber2014-02-28 11:51:04
symfony
Quber, 2014-02-28 11:51:04

How to call Entity Manager in KnpMenu in Symfony 2?

There is a service that implements Breadcrumbs using KnpMenu

services:
    app.one:
        class: App\AdminBundle\Menu\BreadscampBuilder
        arguments:
            - ["@knp_menu.factory"]
    app.breadcrumb:
        class: Knp\Menu\MenuItem
        factory_service: app.one
        factory_method: createBreadcrumbMenu
        arguments: ["@request"]
        scope: request
        tags:
            - { name: knp_menu.menu, alias: breadcrumb }

And the class responsible for its formation:
namespace App\AdminBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class BreadscampBuilder
{
    private $factory;

    /**
     * @param FactoryInterface $factory
     */
    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createBreadcrumbMenu(Request $request)
    {
         // Как тут вызвать entityManager ?
     }

        return $menu;
    }
}

How to call the Entity Manager in this class?
stackoverflow.com suggests adding the following:
protected $entityManager;

    public function __construct($entityManager)
    {
        $this->entityManager = $entityManager;
    }

And in the service add an argument:
arguments:
    entityManager: "@doctrine.orm.entity_manager"

But I can't figure out how to add it to the service in my scenario. Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GHua, 2014-02-28
@Quber

What is it, I can not correct the message.

app.one:
        class: App\AdminBundle\Menu\BreadscampBuilder
        arguments:
             - ["@knp_menu.factory", @doctrine.orm.entity_manager]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question