Modern websites comprise, generally, of three main functions which combine to provide an interactive and effective CMS.
- Model – information management and business logic
- View – presenting information to the user
- Controller – dealing with user input and carrying out requests
This Model, View, Controller architecture is known as MVC. Within the context of a typical website usually breaks down as follows:
- Model – Database storage and management scripts, ensuring consistency and performance
- View – Template system including themes, styling and other files associated with the visual representation
- Controller – The scripts that handle user requests, interacting with the Model to effect change or extract data and presenting this to the end-user via the View.
- Your browser sends a http request that specifies the hat and that it should be placed in the shopping cart. This request arrived at the application’s Controller.
- The Controller checks the data to ensure it is valid (i.e. not malformed) and tells the Model to store this data in your customer account (or temporary session).
- The Model checks that such a product exists in the product catalogue and updates the database to store the updated shopping cart information.
- The database reports the result of the update as successful.
- The Model reports to the Controller that the shopping cart was updated.
- The Controller pulls the correct template/style/formatting information from the View.
- The Controller integrates the information returned from the Model with the View.
- The Controller updates the user interface (e.g. the shopping cart icon now shows an extra item).
This is a very simplified example, and many other things actually happen when something is added to a shopping cart, but hopefully it explains the basic concept of the MVC architecture.