如何在PHP中从头开始实现MVC? [英] How to implement MVC from scratch in PHP?

查看:69
本文介绍了如何在PHP中从头开始实现MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP中从头开始实现MVC,因为我想完全控制自己的代码 并且没有现有框架带来的额外负担.有什么建议吗?

I would like to implement MVC from scratch in PHP because I want full control of my own code and no extra bagage from existing frameworks. Anyone who has any advice?

是的,我看过Lerdorfs的文章,看来它毕竟不是很多代码.实际上,我更想拥有一个用于构造应用程序的控制器视图解决方案.我将坚持自己的自制PDO数据访问类.

Yes, I've seen Lerdorfs article and it seems that it ain't so much code after all. Actually I would more like to have a controller-view solution for structuring my application. I'll stick to my own homemade PDO data-access classes.

推荐答案

您的问题有点闻起来像未发明-这里综合征.在这种情况下,我的建议是在可以确定它们已经过全面测试和支持的情况下,忍受现有框架的额外负担. 不要重新发明轮子.

Your question somewhat smells like Not-Invented-Here-Syndrome. In this case, my advice would be to live with the extra baggage of existing frameworks when you can be sure they are thoroughly tested and supported. Don't reinvent the wheel.

另一方面,以上论点将阻止编写新框架.从头开始编写 是学习和理解MVC模式的一个很好的编码练习.

On the other hand, the above argumentation would prevent new frameworks to be written. And writing one from scratch is a good coding exercise to learn and understand the MVC pattern.

因此,如果您真的决心这样做,我的建议是学习 MVC的每个部分是,确实,以及它们如何相互作用.您也将不可避免地遇到 FrontController模式,因此您也将要了解这一点.

So if you are really determined to do it, my suggestion is to learn what each part of MVC is, does and how they interact. You will inevitably come across the FrontController pattern as well, so you will want to learn about this one too.

请注意,您不是唯一想这样做的人:

Note that you are not the only person wanting to do this:

  • http://www.google.de/search?q=front+controller+php
  • http://www.google.de/search?q=build+your+own+mvc+php

还有Rasmus Lerdorf的这篇有趣的文章

And there is also this interesting article by Rasmus Lerdorf

这篇关于如何在PHP中从头开始实现MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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