Symfony: Multiple similar bundles with one master?

时间:2016-04-04 17:02:07

标签: 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

1 个答案:

答案 0 :(得分:5)

您需要将NewsBundle保留在您的应用程序中,并围绕它创建一系列捆绑包,每个要创建的门户网站都有一个捆绑包。

这里不需要捆绑继承。您的门户网站捆绑包取决于NewsBundle,但不会从中继承。

与特定门户网站相关的路由配置,模板和其他行为应该包含在相关的捆绑包中。每个包中都有一个Resources个文件夹;这是您需要放置特定路由,转换,配置和模板的地方。

app/config/routing.yml是中央路由配置文件,您需要引用所有其他routing.yml文件。

至于交换机,我不能详细回答,但我认为应该在服务器应用程序apachenginx(或其他......)中进行设置。< / p>