使用Symfony PHP实现3层架构 [英] Achieving 3-tier architecture with Symfony PHP

查看:91
本文介绍了使用Symfony PHP实现3层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在到目前为止我完成的学校Web项目中,我已经使用3层方法构建了应用程序. 数据层,应用程序和表示层. 我已经将这种体系结构与python和java一起使用,我也希望将其与php一起使用. 我对层之间的通信非常严格,因为这些是分配的要求,并且我可以说我发现它非常好,因为当我尝试一次从mySQL切换到Mongo db时,这非常容易.我只需要更改数据访问对象功能内的代码即可.

In school web projects that I have done until now I have build my applications with a 3-tier approach. A data layer, an application and a presentation layer. I have used this architecture with python and java and I want to use it also with php. I was quite strict in the communication between layers as these were the requirements of the assignments and I can say that I find it quite good, as when I tried once to switch from mySQL to Mongo db, it was quite easy. I just had to change the code inside the function of my Data Access Object.

正如我之前所说,我现在想用php编写一个更大的应用程序,我下载并安装了Symfony2框架,这是一个MVC框架.我的意图是首先使用MySQL测试该应用程序,然后切换并使用Redis对其进行测试.

As I said before I want to write a bigger application now in php and I downloaded and installed the Symfony2 Framework, which is an MVC framework. My intentions is to test the application with MySQL initial and then switch and test it with Redis.

所以myy问题是: 我可以使用框架的功能和所有优点"来编写3层体系结构应用程序,如何分离各层?

So myy question is: Can I use the functionality and all the "goodies" of the framework to write a 3 tier architecture application and how could I separate the layers?

推荐答案

Symfony2本质上不是MVC框架,它只是一堆松散耦合的组件,可以很好地协同工作.首席开发人员对此有博客文章.

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.

您可以选择捆绑包的细粒度,例如,您可以创建一个捆绑包,其中包含纯域对象,业务逻辑和存储库接口,DAO,无论您需要什么. (可选)您可以提供所选ORM的映射配置.现在,您可以创建用于数据访问策略的捆绑包,例如使用doctrine的捆绑包和其他使用redis的捆绑包,以实现存储库接口.

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.

因此您可以为细粒度的捆绑结构而疯狂,但是对于简单的应用程序,您可以将所有这些都放在/src下,或者仅创建一个捆绑有所有实现数据访问策略的捆绑包,然后在应用程序中选择一个捆绑软件的配置.

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.

研究其他捆绑软件的方法还有助于熟悉最佳实践, FOSCommentBundle FOSUserBundle 可能是一个不错的起点.

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

这篇关于使用Symfony PHP实现3层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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