問(wèn)題描述
我想用 PHP 從頭開(kāi)始??實(shí)現(xiàn) MVC 因?yàn)槲蚁胪耆刂莆易约旱拇a并且沒(méi)有來(lái)自現(xiàn)有框架的額外負(fù)擔(dān).任何人有什么建議嗎?
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?
是的,我看過(guò) Lerdorfs 的文章,看來(lái)代碼畢竟不多.實(shí)際上,我更希望有一個(gè)控制器視圖解決方案來(lái)構(gòu)建我的應(yīng)用程序.我將堅(jiān)持使用我自己自制的 PDO 數(shù)據(jù)訪問(wèn)類(lèi).
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.
推薦答案
你的問(wèn)題有點(diǎn)像 Not-Invented-這里-綜合癥.在這種情況下,我的建議是,當(dāng)您可以確定現(xiàn)有框架已經(jīng)過(guò)全面測(cè)試和支持時(shí),要忍受它們的額外負(fù)擔(dān).不要重新發(fā)明輪子.
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.
另一方面,上述論證會(huì)阻止編寫(xiě)新的框架.從頭開(kāi)始編寫(xiě)一個(gè)是學(xué)習(xí)和理解 MVC 模式的一個(gè)很好的編碼練習(xí).
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.
所以如果你真的下定決心去做,我的建議是學(xué)習(xí)MVC的每個(gè)部分是,是,以及它們?nèi)绾蜗嗷プ饔?你也不可避免地會(huì)遇到FrontController 模式,所以你也想了解這個(gè)模式.
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.
請(qǐng)注意,您不是唯一想這樣做的人:
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
這篇關(guān)于如何在 PHP 中從頭實(shí)現(xiàn) MVC?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!