I’m trying to understand MVC thing and so far I know that it’s used to separate business logic from the view logic (something as HTML and CSS), but I fail at point when I need to organize my files.
Lets say that I have 3 files:
- form.php which is displayed to the user, it takes user input and
submits data - process.php which takes and handle data from form.php, then
connects to database and retrieve requested informations - display.php which display processed data (result) from process.php in organized way
So looking at my example:
- form.php would be controller
- process.php would be model and
- display.php would be view
Right?
Wrong, Actually you are mixing Model and Controller in process.php.
form.php and display.php are only interacting with user, they are acting as views.
process.php is acting as both Controller and Model
You should separate the Controller and Model. You can create a separte model.php and do the database stuff there. So if in future you need to change your database stuff. you dont need to touch process.php. Controller and Model will also be separated from each other