1. Using the MVC architecture in web/PHP applications
The PDF of the document is available |HERE|.
The code for the document is available |HERE|.
The MVC (Model-View-Controller) pattern aims to clearly separate the presentation, processing, and data access layers. A web application following this pattern will be structured as follows:
![]() |
Such an architecture is often called a 3-tier or 3-level architecture:
- the user interface is the view (V)
- the application logic is the controller (C)
- the data sources are the model (M)
The user interface is often a web browser, but it could also be a standalone application that sends HTTP requests to the web service over the network and formats the results it receives. The application logic consists of scripts that process user requests. The data source is often a database, but it can also be simple flat files, an LDAP directory, a remote web service, etc. It is in the developer’s best interest to maintain a high degree of independence between these three entities so that if one of them changes, the other two do not have to change, or only minimally.
The MVC architecture is well-suited for web applications written in object-oriented languages. The PHP language (4.x) is not object-oriented. Nevertheless, one can make an effort to structure the code and the application architecture to align more closely with the MVC model:
- We will place the application’s business logic in modules separate from those responsible for managing the request-response dialogue. The MVC architecture becomes as follows:
![]() |
Within the [Application Logic] block, we can distinguish:
- the main program or controller, which serves as the application’s entry point.
- the [Actions] block, a set of scripts responsible for executing the actions requested by the user.
- the [Business Classes] block, which groups the PHP modules necessary for the application’s logic. These are independent of the client. For example, the function that calculates a tax based on certain information provided as parameters does not need to concern itself with how that information was obtained.
- the [Data Access Classes] block, which contains the PHP modules that retrieve the data needed by the controller, often persistent data (databases, files, etc.)
- the view generators that send views as a response to the client.
In the simplest cases, the application logic is often reduced to two modules:
- the [control] module handling client-server communication: processing the request, generating various responses
- the [business logic] module, which receives data to be processed from the [controller] module and provides it with results in return. This [business logic] module then manages access to persistent data itself.

