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.

The model-view-controller pattern in action

The model-view-controller pattern in action - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

The model-view-controller pattern in action

- And here's a framework-based implementation using the Slim micro framework. Once again, the framework is already installed by a composer in your vendor directory. You can just run the example. You should notice that it's effectively identical with what we had before. Because of Slim, we have some improved routing capabilities, but otherwise things work effectively the same as they did before. In this case, we captured the incoming get and routed it to our controller that we had before. We still used module to choose which controller we want to use. In this case we're back to the NumberController. Once we have the contents of the request into the closure, we route it just like we did before. We create the controller and pass the parameters along. The controller itself is unchanged from our earlier example, in that it passes the data along to the model, chooses the view, and combines the two for the output. Finally, the model and view are unchanged also. They simply take the input…

Contents