From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing the model-view-controller pattern

Introducing the model-view-controller pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Introducing the model-view-controller pattern

- Of any of the architectural patterns, the MVC is probably the most common by far. At this point, just about every framework out there, even the micro frameworks have some sort of MVC concept driving their design. So hopefully, everyone listening to this already has some familiarity with it. While familiarity is great, let's talk about the reason that drives it. The problem is simple, spaghetti code. In many PHP applications, the code to query objects is mixed with the HTML generation, which is mixed with the routing mechanism. It's all wrapped together in a nasty mess of complexity which is challenging to figure out. We want to add new functionality and share components. This challenge becomes nearly impossible. If only there was a way to separate these things out and make components reusable. And voila, we have the MVC pattern. In the simplest terms, the View is the representation of the data to the user. This could be HTML, JSON or whatever is required at the time. The Model is…

Contents