3
votes

I'm just working through the Symfony2 Bible and I'm a little stuck on the bundle system. It is a great feature but I'm not quite sure how to split my flat PHP application into bundles. It's my first time splitting my PHP code into a full featured MVC framework.

I'm working on a few online games (based on PHP) but how would I define the bundles ? Is it like one single onlinegame1 bundle with all the controllers and functions - Or like a login bundle, a register bundle, a war bundle - summarized one bundle for every single PHP file I got ?

I want to start clean and correct but I'm not quite sure if I understand that feature.

1
Bascially you can put inside a Bundle whatever you like :) I suggest you start with something small an play around a bit before porting a whole application, so you get a feeling first and you have room to do mistakes and play around. E.g you could try to integrate an existing user bundle that handles authentication and account management.hakre
Thanks I think I am going to do that. I should end up understanding it when the time is right :)codepushr

1 Answers

7
votes

You could think of bundle as an independent reusable component - in most of the cases at least.

Let's imagine a personal blog website. I'd split it into ArticleBundle, UserBundle, CommentBundle and finally MainBundle which would stick all these other bundles together, creating your website. The main point is that you can take for example ArticleBundle and reuse it easily on other project without it being tied to any other bundle.

From Symfony2 book:

A bundle is similar to a plugin in other software, but even better. The key difference is that everything is a bundle in Symfony2, including both the core framework functionality and the code written for your application. Bundles are first-class citizens in Symfony2. This gives you the flexibility to use pre-built features packaged in third-party bundles or to distribute your own bundles. It makes it easy to pick and choose which features to enable in your application and to optimize them the way you want.