How to implement MVC from scratch in PHP?(如何在 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
这篇关于如何在 PHP 中从头实现 MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 中从头实现 MVC?
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01