Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For what would I make a bundle? (Symfony 2)

Tags:

symfony

bundle

Oke so I am about to make a website using symfony 2.

Should I just make a "main" bundle that controls/puts together all other bundles? With other bundles I am thinking of lets say a "gallery" bundle that controls things related to photos, and a "store" bundle that controls a shop part.

What would be best (or atleast good) practice and how would professional teams do it?

like image 969
Mats Rietdijk Avatar asked Aug 13 '12 13:08

Mats Rietdijk


3 Answers

According to symfony documentation a bundle should be consistent and closed structure. So, if for example "store" and "gallery" are related in some way (eg. use the same model), then they should be in one bundle (AppBundle, CoreBundle, PlatformBundle - whatever you want). But if gallery is completely separate piece of code and can be easily join to another project - then you should consider exclude it to separate bundle.

I think a good idea is look at some projects on github and look how others handle this.

like image 106
Cyprian Avatar answered Nov 01 '22 17:11

Cyprian


See the following questions and my answers to them:

  • Should everything really be a bundle in Symfony 2?
  • Symfony2 conceptual issue: general bundles vs. specific ones

Basically, in my last projects I'm not using bundles for app specific code; the only exception is for stuff that's hardcoded to be in a bundle — like Doctrine Fixtures — that I put in AppBundle. Everything else — models, controllers, services, form types, etc — are out of any bundle.

like image 36
Elnur Abdurrakhimov Avatar answered Nov 01 '22 19:11

Elnur Abdurrakhimov


Like @Cyprian said a bundle is a set of functionality that can work alone. As it happens while developing we do not always know when things are separate. It comes with time.

Personally, I am working with Symfony2 since Febuary and I never stopped reading the manual and related books to understand more in depth. That helped a lot and is very interesting read, I assure you :)

Here is my top favourites documentation pages, en enlightening blog posts on delicious.

For your immediate question, forget about "frontend" and "backend" as we were doing in symfony 1.x. Just think of Model entities (as in A SINGLE row) and build in one bundle. As your code will grow, you will see how to disassemble and separate in bundles. You just have to keep in mind to separate your functionnalities in small methods and refactor around.

like image 39
renoirb Avatar answered Nov 01 '22 19:11

renoirb