Why should I use MVC in a php website? [closed]

人盡茶涼 提交于 2020-01-12 09:52:58

问题


Many frameworks are based on mvc, but I have no idea about MVC. So what is the use of MVC? Is it for speed, security or any other reason?


回答1:


MVC allows you to separate your business logic from your presentation layer. This "Separation of Concerns" allows you to quickly find and edit portions of your code. It also enables easy reuse of your UI components across your system.

Check out the wiki page for a overly academic and technical introduction to MVC http://en.wikipedia.org/wiki/Model_view_controller




回答2:


MVC is mostly for better maintainability of your code. By separating the database logic from the presentational logic from the controller logic you can make changes/rewrites/maintence more easily.




回答3:


it also solves the problem of "spaghetti code", you can outsorce your HTML/XML/PDF/XSL creation Code to your View/Template engine, get the Data from Your Model(DB/File/RemoteCall,...) and your Controller controls the behaviour of Both, you can also simply exchange the View/Models without even Change the Controller if u implement it right, so you gain Seperation of Concerncs, get better Code & Maintainability and can easily swap components also its easier to manage if your projects grow. I recommend the Usage of a FrontController which selects the right Controller for you depending on the Users input, you can also use Inversion of Control/DependencyInjection Pattern there and let your Controller be configued by your FrontController / Pass DB Connection and lots of lots of lots more funny stuff Now u got a simple application framwork:) Use Zend Instead:)



来源:https://stackoverflow.com/questions/3936345/why-should-i-use-mvc-in-a-php-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!