如何实现多层次的体系结构在PHP [英] How To Implement Multi Layered Architecture in PHP

查看:137
本文介绍了如何实现多层次的体系结构在PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经确定了以下的层在我的应用程序中实现。据我所知多层架构是prefered企业应用程序。


  • presentation层
  • 业务层

  • 数据访问层

  • 服务层

我选择的Symfony2以在应用程序中使用的框架。 Symfony2中有MVC架构内置到它。和上述层如下面存在


  • presentation层=>控制器和放大器;查看

  • 业务层,服务层=>模型

  • 数据访问层=>另外的模式,而是使用原则。

模式是由与业务层,数据访问层,服务层。见下面的图片

我的问题是,

有没有办法去耦模型为单独的业务层,数据访问层,服务层?如何实现多层体系结构在PHP?我应该使用一些其他的框架(如果只有它支持分层的体系结构)?

更新

下面的链接是有帮助的。

应如何模型MVC的结构?

<一个href=\"http://stackoverflow.com/questions/2539522/how-to-build-n-layered-web-architecture-with-php\">How用PHP构建正分层的网络架构?

<一个href=\"http://stackoverflow.com/questions/2843311/what-is-difference-of-developing-a-website-in-mvc-and-3-tier-or-n-tier-architect\">What正在开发中的MVC一个网站和3层或N层架构?差

<一个href=\"http://stackoverflow.com/questions/1135056/mvc-application-how-does-mult-tier-architecture-fit-in\">MVC应用。如何MULT层体系结构适合吗?

<一个href=\"http://stackoverflow.com/questions/1352063/implementing-a-service-layer-in-an-mvc-architecture\">Implementing在MVC架构一个服务层

<一个href=\"http://stackoverflow.com/questions/9484458/achieving-3-tier-architecture-with-symfony-php\">Achieving三层架构的Symfony PHP


解决方案

  

<子>如果你是认真的,甚至试图使一些MVC风格,那么你唯一的选择是Synfony和Zend。其他人都只是难过Rails的克隆,实现 PAC 一些私生子。而Sf2.x似乎更好二一..但是这就像在辅导班指出最聪明的孩子。结果
  除非你有能力并且愿意作出自己的框架,Sf2.x将是你最好的选择。


我觉得这里的主要问题是什么误会模式MVC是。模型是一个层,没有任何特定的类或对象。在从Fowler的书图片,一起在 MVC模式将全部三个同心圆。

您基本上在MVC两大层:模型层和presentation层。在presentation层通过服务来与模型层交互,让您抽象垫层域的业务逻辑。

不要混淆域模型。领域模型是描述从客户的业务,即在创建应用中所使用的所有的知识和专长的想法。通常它会被重新presented作为并相互作用说的对象。

对象

此外,这张照片是有点误导。数据抽象层(通常为数据映射器收集实施)是不是低层次结构,那么域模型。这两个域对象和存储抽象是使用由服务(直接或通过库和放大器;工作单位)。它被称为应用逻辑与是服务的直接责任。

底线:不,你并不需要挑选一些不同的框架。你只需要更多地了解应用程序体系结构。你应该阅读企业应用架构的模式 ..这将是一个良好的开端。

<大骨节病>我的2美分

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

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) ?

Update

Below link was helpful

How should a model be structured in MVC?

How to build n-layered web architecture with PHP?

What is difference of developing a website in MVC and 3-Tier or N-tier architecture?

MVC application. How does mult-tier architecture fit in?

Implementing a service layer in an MVC architecture

Achieving 3-tier architecture with Symfony PHP

解决方案

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

这篇关于如何实现多层次的体系结构在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆