Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC, am I doing it wrong?

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?

like image 707
user1134496 Avatar asked Jan 06 '12 14:01

user1134496


2 Answers

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

like image 79
Rajesh Pantula Avatar answered Nov 19 '22 12:11

Rajesh Pantula


I'd say more like

  • form.php - View
  • process.php - Controller
  • display.php - View

There is no actual model. If you have a data structure to represent the data in someDataClass.php, that would be a model.

What you want is to separate the UI (view), the data processing(controller) and the data definition(model).

like image 37
warhead Avatar answered Nov 19 '22 12:11

warhead