Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony: Multiple similar bundles with one master?

Tags:

symfony

Let's say I have created a news portal bundle "NewsBundle" with articles, tags, events, lots of relations, quite huge and complex.

Now I want to copy this numerous times and create a Fashion News Portal, Car News Portal, Dog News portal and so on each available though an own domain. The portals differ only in templates, translations and assets. As I want to implement complex reporting, I want all the stuff in a single database and would flag all entities with the respective portal.

My question: How so I organize the code?

First I figured out, I could use routing to have the same application but different bundles for each domain.

Then I found out, that I could extend my master bundle. But it seems as this works only once.

As I did all the routing with annotations, it look like it does not work to inherit the routes from the master?

One of the hardest questions is where to put the portal switch. Somewhere I need to set a variable that tells whether its the fashion or dogs portal, so I can filter the content in all repositories accordingly.

I did that in the app.php which is for sure worst practise.

In the end I want to be able to roll out new portals easily without duplicate code.

Any ideas are much appreciated.

Greetings from Hamburg, Boris

like image 929
Boris Crismancich Avatar asked Mar 12 '23 17:03

Boris Crismancich


1 Answers

You need to keep your NewsBundle in your application, and to have a number of bundles revolving around it, one for each portal you intend to create.

There is no real need for bundle inheritance here. Your portal bundles depends on the NewsBundle but don't inherit from it.

Routing configuration, templating, and other behaviours related to a specific portal should go in the related bundle. There is a Resources folder in each bundle ; this is where you will need to put specific routing, translation, configuration and templates.

app/config/routing.yml is the central routing conf file where you will need to reference all other routing.yml file.

As for the switch, well, I can't answer that in detail but I think it should be set up in your server application apache or nginx (or other...).

like image 168
Zephyr Avatar answered May 02 '23 18:05

Zephyr