PHP项目具有优秀的OOP设计,适合学习

发布于 2024-09-16 10:16:14 字数 393 浏览 6 评论 0原文

我最近对 ​​Web 应用程序中正确的 OOP 设计产生了兴趣。我认为我理解大部分原则和设计模式,但有时我在将它们付诸实践时遇到问题。

我使用 MVC,我认为我能够以 OOP 方式设计控制器和视图。我面临的问题是模型。我特别着迷于依赖注入和控制反转。它在小例子中工作得很好,但我在设计复杂的多层模型时遇到了麻烦 - 我正在考虑将依赖项注入较低层的各种方法等。

所以我决定寻找一些由更有经验的 OOP 程序员制作的项目,我可以研究它们。我正在寻找 PHP Web 应用程序,最好是用 MVC 架构模式制作的。另外,我不介意它是否具有贫血模型(通常被认为是反模式,但在基于大量数据的应用程序中,我经常被迫使用贫血模型)。

多谢。

编辑:我不是在寻找框架,而是在寻找完整的应用程序。框架通常与模型架构没有太多关系。

I've recently became interested in proper OOP design in web applications. I think I understand most of the principles and design patterns but sometimes I have problem with putting them into practice.

I use MVC and I think I am able to design controllers and views in OOP way. The problem I face is with models. I'm particularly obsessed with dependency injection and inversion of control in general. It works nice in small examples but I have trouble to design complex multi layered models - I'm thinking about various ways to inject dependencies into lower layers etc.

So I decided to look for some projects made by more experienced OOP programmers which I could study. I'm looking for PHP web application, preferably made with MVC architectural pattern. Also I don't mind if it has anemic model (which is usually considered to be antipattern but in heavy data based applications I'm often forced to use anemic models).

Thanks a lot.

EDIT: I'm not looking for a framework but for a complete application. Frameworks usually have not a lot of to do with model architecture.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

快乐很简单 2024-09-23 10:16:14

代码igniter是php4,我不太推荐它。从那时起,PHP OOP 发生了变化。更好的主意是 kohana

我通过查看 构建。创建者也对 SO 半活跃 =)

Code igniter is php4, i don't recommend it too much. PHP OOP has changed since then. A better idea would be kohana

I learned a lot by checking out Konstrukt. The creator is semi active on SO too =)

黑寡妇 2024-09-23 10:16:14

Magento Commerce 有复杂的多层模型(www.magentocommerce.com),您可以从中学到一两个技巧。

但我(个人)使用 Magento 的经历令人沮丧:我在 0.8-1.1 版本左右使用它,它似乎设计过度且文档记录不足。试图弄清楚它实际上是如何工作的很复杂:您最终会在编辑器中打开大量文件,其中大多数称为 Abstract.php。希望从那时起事情已经有了很大的改善。

Magento Commerce has complex multi layered models (www.magentocommerce.com) which you may pick up a trick or two from.

But my (personal) experience with Magento was frustrating: I was hacking with it around version 0.8-1.1 and it appeared over engineered and poorly documented. Trying to figure out how it actually worked was complex: you'd end up with tons files open in your editor, most of them called Abstract.php. Hopefully things have improved a long way since then.

浪荡不羁 2024-09-23 10:16:14

我建议您看一下 Symfony 2。

它可能是您会发现的设计最好的 PHP 项目。它是SOLIDDRY 并在适用的情况下使用模式。

I recommend you take a look at Symfony 2.

It is probably the best designed PHP project you'll find. It's SOLID, DRY and uses patterns where applicable.

黯淡〆 2024-09-23 10:16:14

您在“模型”方面面临的问题到底是什么?您谈论依赖注入,但这实际上与 MVC 上下文中的“模型”概念无关。如果您正在寻找如何管理和沿对象层次结构传递依赖项的示例,您可能需要查看 Symfony 2.0 的依赖项注入容器实现。

What exactly is the problem you are facing with "Models"? You talk about Dependency Injection, but that really has nothing to do with the concept of a "Model" in the MVC context. If you are looking for examples of how to manage and pass dependencies down object hierarchies, you might want to take a look at Symfony 2.0's Dependency Injection Container implementation.

煞人兵器 2024-09-23 10:16:14

我强烈推荐 Nettuts+ 上的 CodeIgniter 从头开始​​系列。

http://net.tutsplus.com/tutorials /php/codeigniter-from-scratch-profiling-benchmarking-hooks/

编辑:@Galen

这是不正确的。 CodeIgniter 从 1.7.2 版本开始支持 PHP 5.3.0。

I highly recommend the CodeIgniter from scratch series on Nettuts+.

http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-profiling-benchmarking-hooks/

EDIT: @Galen

This is not correct. CodeIgniter supports PHP 5.3.0 since version 1.7.2.

送你一个梦 2024-09-23 10:16:14

如果您正在寻找“优秀的 OOP 设计”,那么您可能找错了方向。 PHP 的 OOP 模式并不是很强。如果您的学习和情况允许,我建议您转而研究 Java 项目。

If you're looking for "excellent OOP design" you're probably looking into the wrong corner. PHP is not very strong at it's OOP patterns. If your study and situation permits I recommend you looking into a Java project instead.

筱果果 2024-09-23 10:16:14

CodeIgniter 框架是一个不错的学习源

The CodeIgniter framework comes to mind as a decent study source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文