Mats Rietdijk
Mats Rietdijk

Reputation: 2576

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

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?

Upvotes: 7

Views: 2308

Answers (3)

renoirb
renoirb

Reputation: 559

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.

Upvotes: 1

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44851

See the following questions and my answers to them:

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.

Upvotes: 2

Cyprian
Cyprian

Reputation: 11374

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.

Upvotes: 3

Related Questions