CIST 2550 PHP Chapter 5

Teresa Stillings

Exercise 5-1

Explain the MVC pattern; for example its components, purpose, benefits, etc.

MVC (Model-View-Controller) pattern

The basic pattern consists of the model, view, and the controller. You want each layer to be as independent as possible.

The model is usually your database files. The main connection to the database and the product, category data that works with the database. They are the PHP files that represent the data of the application. The model files do not have any HTML.

The view consists of the HTML and PHP files that represent the user interface of the application. This is what is displayed on the web pages. View files contain HTML tags with some embedded PHP tags that display the dynamic data that’s returned from the database.

The controller consists of the PHP files that receive HTTP requests from browsers/users, get the appropriate data from the model, and return the appropriate views to the browsers/users.

The benefits of using MVC pattern makes it easier to code, test, debug, and maintain because it breaks everything down into separate components.

The purpose is to allow multiple people to work on the project at the same time each working on the separate components. The division of labor is important for large websites that have multiple web designers and PHP programmers.