Ghassan Idriss
Ghassan Idriss

Reputation: 2118

Access to Doctrine during Bundle Initialization

I have a Symfony2 bundle which I want to use database table which stores key value configuration parameters. I want to be able to load a query and cache it for a long time and be able to inject the configuration parameters into symfony2 service container.

Right now I am injecting a service which loads the configuration from doctrine, and calling a get($key) method to retrieve the value for the key I want.

I basically want these configuration options to be available from the symfony2 service container parameter bag.

Is there maybe an event I could tie into or some sort of compiler pass I can use with my bundle to achieve this?

Upvotes: 0

Views: 294

Answers (1)

Clotaire
Clotaire

Reputation: 71

I'll do something like that in your service listener

public function onLateKernelRequest(GetResponseEvent $event)
{
    $request = $event->getRequest();
    $mydata= $this->manager->getRepository('YourBundle:YourTable')->getAll();

    $parameters['mydata'] = $mydata;
    $request->attributes->add($parameters);


}

In your Controller, you can get your parameters :

$this->container->get('request')->attributes->get('mydata');

Upvotes: 2

Related Questions