Tutorial PHP / MVC
The goal of this tutorial is to start from a one-page website and gradually
transform its structure into a model view controller pattern (MVC)
1 Question 1
• Look at the [Link] file that is in the stage0 directory.
• Add the corresponding database.
• Run the [Link] file by copying it to your WWW or htdocs directory on
your server (WAMP, MAMP, Xampp, etc.).
• What does it do?
• How do you find the code in terms of readability and ease of modification?
2 Question 2: The model
• Find the code snippets in the previous file that allow you to write SQL
queries.
• Copy the database access code into a file called [Link] and
include it in your [Link].
• Encapsulate this code in c-functions and use function calls.
• Move these functions to a file called [Link], which you will call in the
[Link] file through a request. This file should be in a directory model.
• Test the code
3 Question 3: The views
• Find the code snippets in the previous file that allow you to write HTML
code.
• Move the HTML content into two files: [Link] for adding or modifying a
user and [Link] for displaying the list of users. These two files should be in a
directory called views.
• Edit the index file to include these files
• Test the code
4 Question 4: Going even further with MVC
• Examine the code in step3
• Test the code