如何在 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.
推荐答案
你的问题有点像 Not-Invented-这里-综合症.在这种情况下,我的建议是,当您可以确定现有框架已经过全面测试和支持时,要忍受它们的额外负担.不要重新发明轮子.
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+控制器+php
- http://www.google.de/search?q=build+your+own+mvc+php
还有 Rasmus Lerdorf 的这篇有趣的文章
And there is also this interesting article by Rasmus Lerdorf
- http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html
相关文章