Create CodeIgniter View

The CodeIgniter View is the information that is being presented to a user. CodeIgniter View will normally be a web page in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an page, or any other type of page.They are the interface design which is displayed on the user's browser and can never be called directly, they have to be loaded in the controller file.

Create a CodeIgniter file and save it in application/views folder. For example How to web code.php.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="description">
  <meta content="" name="keywords">
    <title>Codeigniter Tutorial - How to web code</title>
</head>
<body>
    <h3>This is view page .</h3>
</body>
</html>

Loading a View

$this->load->view('page_name'); 

Loading a View in controller page .

<?php

    defined('BASEPATH') OR exit('No direct script access allowed');

    class Codeigniter extends CI_Controller {

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

?>
                

Adding Dynamic Data to the View

CodeIgniter Data is passed from the controller to the view by way of an array or an object in the second parameter of the view loading method. Here is an example using an array :

$data = array(
    'id' => 10,
    'name' => 'My name'
);

$this->load->view('codeigniter/index', $data);