I have identified below layers to be implemented in my application. According to my knowledge multi layered architecture is prefered for an enterprise application.
- Presentation Layer
- Business Layer
- Data Access Layer
- Service Layer
I have chosen Symfony2 as the framework to be used in the app. Symfony2 has MVC architecture built into it. And the above layers exist as below.
- Presentation Layer => Controller & Views
- Business Layer, Service Layer => Model
- Data Access Layer => Also Model but Doctrine is used.
Model is consisted with Business Layer, Data Access Layer, Service Layer. See the below image that is borrowed from Martin Fowler’s book, Patterns of Enterprise Application Architecture.
My problem is,
is there a way to decouple the model into separate Business Layer, Data Access Layer, Service Layer ? How to implement multi Layered architecture in PHP ? Should I use some other framework(If only it supports layered architecture) ?
Below link was helpful
If you are serious about even trying to make something MVC-inspired, then your only options are Synfony and Zend. The others are just sad Rails-clones, that implement some bastardization of PAC. And Sf2.x seems to better one of two .. but that’s like pointing out smartest kid in the remedial class.
Unless you are able and willing to make your own framework, Sf2.x will be your best bet.
I think the main problem here is the misunderstanding what “model” in MVC is. Model is a layer, not any specific class or object. In the picture from Fowler’s book, the “MVC model” will be all three concentric circles taken together.
You basically have two major layer in MVC: model layer and presentation layer. The presentation layer interacts with model layer through services, that let you abstract the underlaying domain business logic.
Do not confuse it with “domain model“. Domain model is an idea that describes all the knowledge and expertise from client’s business, that is used in creation of application. Usually it will be represented as separate domain objects and the interaction of said objects.
Also, this picture is somewhat misleading. The data abstraction layer (usually implemented as collection of data mappers) is not lower level structure then domain model. Both domain objects and storage abstractions are uses by service (either directly or through repositories & units of work). It is referred to as “application logic” and is a direct responsibility of services.
Bottom line: no, you do not need to pick some different framework. You only need to learn more about application architecture. You should read Patterns of Enterprise Application Architecture .. that would be a good place to start.
My 2 cents