GregOs
GregOs

Reputation: 403

Override parameters.yml in each bundle symfony2

I'm working on a complex Symfony project. In the project, we have a core bundle which uses the parameters.yml located in app/config.

Each other AppBundle will inherit this CoreBundle and will correspond to a website.

What I need is to have specific parameters in each bundle that will override the default parameters one: when I'll use a route that will bring me into a controller's bundle, the parameters of this specific bundle have to override all the other ones.

I've tried the preprend method but it doesn't fit to this need. It only allows me to create new parameters for this bundle, but not to override the other ones.

Upvotes: 1

Views: 1241

Answers (2)

GregOs
GregOs

Reputation: 403

Solution found thanks to dragoste's asking about separated kernels.

To solve my problem, I had to split the kernels : one for each website.

Documentation can be found here :

http://jolicode.com/blog/multiple-applications-with-symfony2

Upvotes: 0

Jakub Matczak
Jakub Matczak

Reputation: 15656

I think you misunderstand the idea of bundles in Symfony. Bundle by design should be a reusable module, therefore the configuration placed inside a bundle is the default one. Then it is possible to override parameters (and not only!) in configuration in app folder.

The basic idea is:

Bundles don't use application. Application uses bundles.

So it's completely the opposite to what you expect it to be. Acutally it makes no sense to condition whole application configuration depending on current route since bundles can use one another. What if your currenct action will internally (without redirect) call another bundle's service or even controller?

Also it's worth mentioning that the app folder is the final folder for your application, therefore you can override in it not only bundle's configuration but also other things like services, view templates and so on.

Edit: I forgot to suggest a solution for you :)

Since you want to use custom parameters inside bundle, why do you need the default value in first place? Just create separate parameter namespace for each bundle that won't be overridden by application config. Then use it only inside that bundle.

Upvotes: 4

Related Questions