7

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?

Mats Rietdijk
  • 2,576
  • 3
  • 20
  • 25

3 Answers3

3

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.

Cyprian
  • 11,174
  • 1
  • 48
  • 45
  • I actually dont know how github works or how to find a project that would match what I want to do in a decent amount of time. But what you say is: make 1 bundle (appBundle or coreBundle) that will have the basic website and then for special parts which could be used for other projects (gallery and store) have their own bundle? – Mats Rietdijk Aug 13 '12 at 14:51
  • Yes - exactly. This approach has several advantages. Eg 1) It's slightly more efficient 2) You can see what you can use in another places on first sight. 3) IMO there is easier to manage your tests in this way 4) Your app is more "portable". Apart from independent parts of your app, you can consider create separate bundle for util things (like let's say some Math class or class defines http statuses etc) or part which logically is very different from application (eg. AdminBundle). And generally after a lot of explorations I discovered this the most convenient and popular solution. – Cyprian Aug 14 '12 at 08:42
2

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.

Community
  • 1
  • 1
Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • Thanks for your anwser, I am new to symfony2 at the moment so changing alot on the basic setup might not be a smart thing for now. But I will have a look at this approach. – Mats Rietdijk Aug 14 '12 at 13:23
  • Hey Elnur, I've read some of your other threads and I'm not grasping how you place things like controllers, forms, etc outside of any Bundle. How does that work exactly? What purpose does bundles serve for you then actually? – Andy Baird Aug 15 '12 at 05:18
  • I'm planning to expand my answer on the first question from the list I gave here with examples of defining controllers, forms, etc outside of bundles. Just need some time. – Elnur Abdurrakhimov Aug 15 '12 at 06:14
  • Added a section on using controllers out of bundles to [my answer](http://stackoverflow.com/a/10001019/745188). – Elnur Abdurrakhimov Aug 15 '12 at 06:48
1

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.

renoirb
  • 569
  • 5
  • 15