0

I am trying to understand MVC, but for most of the Q&A's I have seen, the description is great but I cannot quite understand it, I think it works like this scenario I thought of:

User Registration (sorry for the wrong order):

  • Controller: The user, they input the data (username & password)
  • Model: The UserRegistration class - Takes in the username and password and deals with the request
  • View: A success message passed to the user (just an example!)

Am I right in thinking that it goes the same for any language; C#, C++, PHP etc.?

I have tried for ages to understand this and what I am looking for is: talk to me like I am a child or a monkey.

I have looked here (What is MVC, really?) and found it didn't help me

1 Answers1

3

As your example of user registration:

  • Model: This would be your "User" class which is populated at the end of registration, that stores the Username, Email, Password, etc. This would then be put into the database.
  • View: The HTML page which allows the user to input their desired Username, Email, Password, and click submit.
  • Controller: Gives the View to the User initially so they can fill out the registration form. Then takes the details from the View, uses them to populate the Model and create a record in the database.

An easy way of looking at it is that the Controller acts as a bridge between Model and View. If you wish to retrieve data from a db, the Controller accesses the Model layer, and passes the data down into the view. If you want to store data, the data you enter into the view is passed to the Controller which runs logic (validation, modification) on the user submitted data, creates the Model using that data, and stores it in the database.

FLSH
  • 159