Skip to content

00. Introduction

Simon Striekwold edited this page Oct 4, 2019 · 6 revisions

Introduction to MVC

Using the MVC design pattern a website is split into three parts:

  • Model:

    The model is an object representation of a database row, it's properties are the database columns, and it's methods are used to manipulate the data (for example: save(), delete()).

    The model also contains static methods to get data from the database, and contains information about the data.

    For more specific information see the wiki entry for Model.

  • View:

    The view is what the user sees, it contains only HTML and supporting php, such as loops and if statements.

  • Controller:

    The controller is the bridge between the model and the view. It gets data from the model applies some business logic to it and then sends the data to the view to be displayed.

    For more specific information see the wiki entry for Controller.

What happens when a page is loaded

  1. URL-Routing: The default url scheme is /controller/action, so for example /users/login loads the users controller and the login action.

  2. Config: The config is initialized.

  3. Controller/Action: The request arrives at the specified controller/action.

  4. Model: Some data is requested from the model.

  5. Controller/Action: Some business logic is applied.

  6. Layout: The layout is renderd.

  7. View: The view is rendered within it.

Components

The following are some basic components and what they do:

  • Setup: Automatically creates your database and loads it with test data. If the database already exists it resets the database and loads it with clean test data.

  • Default helpers: Some functions to simplify common tasks, like redirect, GenerateId, UploadFile, etc.

  • Sql: Wrapper for PDO sql queries, for example

    $user = Sql::find('user')->where(['id' => $id])->one();
  • Load-Validate: A pair of model methods to simplify the validation of post data.

    Load: Loads (post) data into the properties of it's model.

    Validate: Checks the properties against the rules of it's model.

Clone this wiki locally