Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've read a lot of different things about bundles and the architecture of a Symfony2 project, however I've yet to come to a conclusion on the best practice for an individual project which isn't concerned with re-using bundles etc. The reason being that this is a client specific project.

The application is a large website with different sections such as News, Blog, Multi step application form, Contact, Testimonials etc. Each section will need backend and front end functionality e.g News articles can be added by an administrator in the backend and can be viewed in the front end. THe backend will contain some backend only functionality such as Admin Users and will have an admin log which will log the activity of each admin user, therefore this needs to be accessible within each backend section.

I initially thought about having different bundles for each section i.e AdminUserBundle, NewsBUndle, BlogBundle etc before I quickly realised there is a lot of shared layouts/templates and functionality (such as AdminLog). Therefore, what would you suggest would be best practice for this kind of project? I think I've got three options but open to additional suggestions:

  1. 1 bundle for all with backend and frontend directories within Controller, Views, Tests etc.
  2. 3 bundles - CoreBundle, FrontendBundle and BackendBundle where CoreBundle will contain all shared functionality such as Entities, AdminLog etc.
  3. A bundle for each section with Frontend and Backend directories within Controller, Views, Tests etc. I.e NewsBundle will contain the News Entity and will contain frontend and backend Controllers, Views and Tests. BlogBundle will contain the Blog Entity and frontend and backend COntrollers, Views, Tests etc.

Thanks

share|improve this question
Since reuse is not an issue, I'd go with option 1. You can always break things up if it becomes too unwieldy. – Cerad May 16 at 21:29
Thanks. I think this way though makes it a little untidy as you could have lots and lots of controllers/views etc in the one folder. If we have a separate bundle for each feature it's easier to navigate and find the code for the particular section you're working on. – user1961082 May 17 at 11:07

1 Answer

up vote 1 down vote accepted

According to the Symfony2 documentation:

In Symfony2, a bundle is like a plugin, except that all of the code in your application will live inside a bundle. A bundle is nothing more than a directory that houses everything related to a specific feature, including PHP classes, configuration, and even stylesheets and Javascript files (see The Bundle System).

A Bundle should resolve a business/functional problematic. So I think the third suggestion is a good solution.

You can have a CoreBundle with contains technical problematic like global forms type, forms theme, custom doctrine functions. This bundle doesn't contains business problematic.

And other bundles should only contains business problematic like a bundle for News an other for Blog another for Comments ...

Hope it's helpful.

Best regard

share|improve this answer
Thanks. I think im going to go with this method. – user1961082 May 17 at 11:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.