0

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?

Ghassan Idriss
  • 2,120
  • 20
  • 16

1 Answers1

2

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');
Clotaire
  • 71
  • 5