How is MVC supposed to work in CodeIgniter

前端 未结 3 730
春和景丽
春和景丽 2020-12-04 22:52

As a mostly self-taught programmer I\'m late to the game when it comes to design patterns and such. I\'m writing a labor management webapp using CodeIgniter.

I did a

3条回答
  •  失恋的感觉
    2020-12-04 23:58

    Despite its claims to the contrary, Codeigniter does not use MVC at all (In fact, very few web frameworks do!) it actually uses a PAC (Presentation-abstraction-control) architecture. Essentially, in PAC the presentation layer is fed data by a presenter (which CodeIgniter calls a controller) and in MVC the View gets its own data from the model. The confusion exists because of this mislabeling of MVC.

    As such, CodeIgniter (and most of the other popular web frameworks) don't encourage a proper model but just use very rudimentary data access its place. This causes a large set of problems because of "fat controllers". None of the code which relates to the domain becomes reusable.

    Further reading:

    • MVC vs. PAC

    • The M in MVC: Why Models are Misunderstood and Unappreciated

    • Model-View-Confusion part 1: The View gets its own data from the Model

    • The Fat Controller

    This is a widespread point of confusion in the PHP Community (The MVC vs. PAC article identifies the problem as stemming from the PHP community. that was written in 2006 and nothing has changed, if anything it's got worse because there are more frameworks and tutorials teaching an erroneous definition of MVC.) and why people looking at "MVC" PHP code who have come from a background outside web development understandably become confused. Most "MVC" implementations in PHP are not MVC. You are correct in thinking models should be properly structured, it's CodeIgniter that's wrong to label itself as MVC.

提交回复
热议问题