0

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.

Community
  • 1
  • 1
Mattias
  • 387
  • 1
  • 5
  • 17
  • 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 Sep 13 '17 at 12:42
  • 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 Sep 13 '17 at 13:00
  • 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 Sep 13 '17 at 13:03
  • I'll consider it. But I'd still like to learn so that I can make an educated decision. – Mattias Sep 13 '17 at 13:28

1 Answers1

0

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!

Valentin Knyazev
  • 156
  • 1
  • 11
  • My goal is to have a bundle which is easy to install without too many configuration steps. I might be tackling this the wrong way. In that case I'm open to suggestions. I'm fine with adding 1 or 2 lines of configuration when a bundle is installed. But what if the bundle requires the configuration of both doctrine (db connection) and monolog (channels etc.). This will quickly become a lot of configuration steps. – Mattias Sep 15 '17 at 21:13