MVC Standards for Model-View-Controller. It is a architectural pattern that divides the system into three main parts.

  • The model deals with database communication .
  • The controller directs the functions between the model and the view.
  • View is responsible for data presentation.

How MVC frameworks work?

The following image shows the MVC framework works



CodeIgniter Controller

Open the file Welcome.php controller located application/controllers


application/controllers /Welcome.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {

    public function index() {
        $this->load->view('welcome_message');
    }

}

  • defined('BASEPATH') OR exit('No direct script access allowed'); prevents direct access to the controller
  • Welcome controller class and extends the parent class CI_Controller
  • index method that responds to the URL

$this->load->view('welcome_message'); loads the view welcome_message that is located in application/views directory


CodeIgniter Views

application/views/welcome_message.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Welcome to CodeIgniter</title>
    </head>
    <body>

        <div id="container">
            <h1>Welcome to CodeIgniter!</h1>
        </div>

    </body>
</html>

Run the application 

http://localhost/project_name/index.php/controller_name/controller_method


Example in my case:

http://localhost/bcit-ci-CodeIgniter-b73eb19/index.php/Welcome/index