Model-View-Controller Basics

The Model-View-Controller design pattern has become the dominant pattern for web frameworks, particularly the implementation pioneered by Ruby on Rails when it was first released publicly in 2004. The MVC pattern identifies three main components which each have specific responsibilities in handling the web page request.

  • Model: The model is responsible for persistent data, and usually handles all database access.
  • View: The view is responsible for the user interface, including any HTML, CSS or Javascript.
  • Controller: The controller is responsible for processing input (which in the web, comes by way of a request) and invoking the other layers as necessary.

Sodapop's MVC Implementation

Sodapop's MVC implementation is best illustrated through how it interprets a request URL. 1

http://example-domain.com/post/view/slug/this-is-my-post-slug
  • post: the controller name
  • view: the action name
  • slug/this-is-my-post-slug: a request variable, the equivalent of ?slug=this-is-my-post-slug

Within your code, you could then handle this through a controller2 like this:

You could display this using a view file3 like this:

These are the basic components of the Sodapop MVC framework.