Course Content
Introduction to CodeIgniter
CodeIgniter is a powerful PHP framework built for developers who need a simple and elegant toolkit to create full-featured web applications.
0/3
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. The segments in a URI normally follow this pattern:
0/1
Forms and Input
Forms provide a way for users to interact with the application and submit data.
0/1
Composer
Composer is dependency manager in PHP. it allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
0/1
Security
You can enable CSRF protection by modifying your application/config/config.php file
0/1
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
DataTable
DataTables is a table enhancing plug-in for the jQuery Javascript library that helps in adding sorting, paging, and filtering abilities to plain HTML tables with minimal effort. The main goal is to enhance the accessibility of data in normal HTML tables.
0/1
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
Payment Gateway
Razorpay and PayTM Payment Gateway
0/2
Chatbot
WhatsApp Chatbot and Telegram Chatbot
0/2
CodeIgniter 3
    About Lesson

    The View is responsible for presenting data from the Model in a specific format, typically using HTML. Views are simple web pages that display data passed from the Controller, providing a clear separation between the application logic and the presentation layer. This tutorial will guide you through the process of creating, loading, and dynamically adding data to views in CodeIgniter 3.

     

    What is a View in CodeIgniter?

    A View in CodeIgniter is essentially a PHP file that contains HTML and PHP code used to display the data. It is responsible for rendering the user interface of your application. Views are typically loaded by a Controller, which processes the data and passes it to the View for presentation.

     

    How to Create a View in CodeIgniter

    1. Create a basic HTML file to act as your View. Below is an example of a simple view named about_us.php:

     

    <html>
    <head>
    	<title>About Us</title>
    </head>
    <body>
    	<h1>Welcome to infovistar</h1>
    </body>
    </html>

    2. Save this file in the application/views directory of your CodeIgniter project.

     

    View in CodeIgniter

     

    How to Load a View in CodeIgniter

    To load a view, use the $this->load->view() method in a Controller. This function takes the name of the view file (without the .php extension) as its parameter.

    For example,

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

    This line will load the about_us.php file from the application/views directory. The .php extension does not need to be specified unless the view file has a different extension.

     

    Loading a View in a Controller

    Let’s set up a Controller to load the about_us view. Create a new Controller named Welcome.php in the application/controllers directory with the following code:

    class Welcome extends CI_Controller {
    
    	public function about_us() {
    		$this->load->view('about_us');
    	}
    
    }

     

    Adding Dynamic Data to the View

    To make your views more dynamic, you can pass data from the Controller to the View using an array or an object. This is done by passing the data as the second parameter of the $this->load->view() method.

    Here is an example of passing data using an array:

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

     

    1. Create the Welcome.php file in the application/controllers directory and include the about_us method that passes data to the view:

    class Welcome extends CI_Controller {
    
    	public function about_us() {
    		$data = array(
    	        'title' => infovistar.in',
    	        'heading' => About Us',
    	        'message' => 'Welcome to CodeIgniter‘'
    		);
    		$this->load->view('about_us', $data);
    	}
    }
    

     

    2. Create the about_us.php file in the application/views directory. This file will use the dynamic data passed from the Controller:

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

    Views in CodeIgniter

     

    How It Works

    1. Access the View: Open your browser and navigate to http://yourdomain.com/welcome/about_us. This will call the about_us method from the Welcome controller.
    2. Controller Loads the View: The about_us method in the Welcome controller loads the about_us view and passes the dynamic data array to it.
    3. View Displays the Data: The about_us.php view receives the data from the Controller and displays it in the specified HTML format.

     

    Views play a crucial role in separating the presentation layer from the application logic.