Achieving 3-tier architecture with Symfony PHP Achieving 3-tier architecture with Symfony PHP symfony symfony

Achieving 3-tier architecture with Symfony PHP


Symfony2 isn't an MVC framework per se, it's just a bunch of loosely coupled components working nicely together. There is a blog post about this from the lead developer.

You can choose how fine grained your bundles are, for example you can create a bundle with pure domain objects, business logic and interfaces for repositories, DAOs whatever you want. Optionally you can provide mapping configuration of your ORM of choice. Now you can create bundles for the data access strategies, like a bundle working with doctrine, other with redis, implementing your repository interfaces.

So you can go crazy about fine grained bundles structure, but for simple applications you can just put all of these under /src, or just create a bundle with all the data access strategies implemented there, and choosing one in your application with the bundles' configuration.

Studying other bundles' approaches also helps to get familiar with best practices, FOSCommentBundle or FOSUserBundle could be a good place to start.


Sure. Trick is to wrap up your data layer (aka business objects) in services. Your application (aka controllers) interact with these services based on user input and pass the results onto the presentation layer.

Build your services carefully and you will be able to swap out the database layer without impacting your controllers or presentation.