user1961082
user1961082

Reputation: 1035

Symfony2 Bundle/Application Structure (Frontend/Backend)

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

Upvotes: 0

Views: 2927

Answers (1)

Benjamin Lazarecki
Benjamin Lazarecki

Reputation: 2970

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

Upvotes: 1

Related Questions