問題描述
我想用 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!