0
votes

I've just started working with Symfony and have run into a problem that I'm having a hard time tracking down information about.

I'm trying to create a bundle which has its own configuration file, e.g. configuration for doctrine connections.

All documentation I've found have never mentioned of showed how this can be set. Is it possible?

What I want to solve:

I have a bundle which when installed should handle connection to a secondary database table without any configuration needed from the main application in which the bundle has been integrated. Ultimately the configuration in the bundle should be override-able from the main application.

The bundle should be in the lack for a better work "self contained".

I've found documenation about bundle configuration. But all I've seen mentioned there is if one would like to configure the bundle and not interaction with other components (might have missed something).

tl;dr I want to have a config (e.g. AppBundle/Resources/Config/config.yml) file inside a bundle which can configure things like doctrine.

What i've tried

I've tried placing the configuration inside a config.yml file located in Resources/Config/. But I guess the file is never read.

1
The easiest way is to add your config file to the imports: section in app/config/config.yml i.e. - { resource: '@AppBundle/Resources/config/doctrine.yml' } This almost meets your requirements for zero app configuration and is similar to what you need to do to include routes and such. Otherwise I think you will need to enter the wonderful world of Symfony configuration.Cerad
Okey. Do you have any good documentation for "Symfony configuration"? Or is "How to Create Friendly Configuration for a Bundle" in the Symfony doc the best?Mattias
Yep, your link is the starting point but I'd strongly advise just requiring the resource line. I'm not at all sure how you could add doctrine configuration information using an extension. Good luck.Cerad
I'll consider it. But I'd still like to learn so that I can make an educated decision.Mattias

1 Answers

0
votes

I think it is not good idea to put something related to configuration right inside your bundle and ruin it's reusability by doing such thing. As far as I understood your task what your really need is to configure second entity manager to manage entities from secondary database when you need them. Same problem and its solution are described in following question: Doctrine 2 - Multiple databases configuration and use Hope that will help!