MVC Execution Flow
This page explains how a request moves through the MVC framework from the moment a user visits a URL until the final HTML is rendered.
Execution Path
Request ↓ Router ↓ Controller ↓ Model ↓ Database ↓ Controller ↓ View ↓ HTML Output
Step-by-Step Explanation
1. Request
A user visits a URL such as:
/posts/my-article
The web server forwards the request to the MVC application.
2. Router
The router determines which controller should handle the request. It parses the URL and maps it to a controller and method.
3. Controller
The controller receives the request and decides what logic should run. Controllers coordinate communication between models and views.
4. Model
If data is required, the controller calls a model. Models are responsible for interacting with the database.
5. Database
The model executes queries using the approved database wrapper and retrieves data.
6. Controller (again)
The model returns the result to the controller. The controller prepares the data for the view.
7. View
The controller sends the data to the view, which renders HTML. Views should contain minimal logic and focus on presentation.
8. HTML Output
The rendered page is returned to the browser and displayed to the user.
Example Flow
User visits: /posts/my-article Router → posts controller Controller → posts_model Model → database query Model → returns article data Controller → passes data to view View → renders HTML page