Course Content
Introduction to CodeIgniter 4
CodeIgniter is an Application Development Framework. CodeIgniter is a popular and powerful MVC (Model-View-Controller) framework that is used to develop web applications. It is a free and Open-source PHP framework.
0/5
MVC (Model-View-Controller)
MVC stands for Model-View-Controller. MVC is an application design model consisting of three interconnected parts. They include the model (data), the view (user interface), and the controller (processes that handle input).
0/6
Sessions
The Session class allows you to maintain a user’s "state" and track their activity while they browse your site.
0/1
URI Routing
There is a one-to-one relationship between a URL string and its corresponding controller class/method.
0/2
Working with Database
Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides a rich set of functionalities to interact with the database.
0/5
Spreadsheet
PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. Importing Excel and CSV into MySQL help to save the user time and avoid repetitive work.
0/1
CodeIgniter 4
About Lesson

The View is responsible for the presentation of the Model (data) in a certain format. A view is a simple web page created using HTML. We can call a view by using a Controller.

How to create a view?

<html>
<head>
        <title>About Us</title>
</head>
<body>
        <h1>infovistar.com</h1>
</body>
</html>

Save the file as about_us.php in your /app/Views directory.

How to load a view?

The view() method is used to load a view in a Controller.

Load a view in CodeIgniter 3 Load a view in CodeIgniter 4
$this->load->view(‘about_us’); echo view(‘about_us’);

Now we can set this view to our about_us() method in the Home.php controller.

<?php
namespace App\Controllers;	

class Home extends BaseController {

	public function about_us() {
		echo view('about_us');
	}

}
?>

Add dynamic data to the View

We can pass data from the controller to the view by way of an array or an object in the second parameter of the view method.

Here is an example using an array:

$data = array(
        'title' => infovistar.com',
        'heading' => About Us',
        'message' => 'Welcome to CodeIgniter‘'
	);
echo view('about_us', $data);

Example:

Controller: Home.php

<?php
namespace AppControllers;	

class Home extends BaseController {

	public function about_us() {
		$data = array(
		        'title' => 'infovistar.com',
		        'heading' => 'About Us',
		        'message' => 'Welcome to CodeIgniter'
			);
		echo view('about_us', $data);
	}

}
?>

View: about_us.php

<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <h1><?php echo $heading; ?></h1>
    <h6><?php echo $message; ?></h6>
</body>
</html>