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

    In CodeIgniter, you can create a common layout structure using a template file, which helps you manage the header, footer, and dynamic content for each page efficiently. This tutorial will guide you through setting up a basic template structure and using it within your CodeIgniter application.

     

    File Structure

    To implement this template system, you will create the following files:

    applications/view/innerpages
    	- footer.php
    	- header.php
    	- template.php
    
    applications/controllers
    	- Welcome.php

     

    Step 1: Create template.php in application/views/innerpages/

    The template.php file acts as the main layout template that loads the header, footer, and dynamic content based on the page being accessed.

    File: application/views/innerpages/template.php

    <?php 
    	$this->load->view('innerpages/header.php');
    	$this->load->view($main_content);
    	$this->load->view('innerpages/footer.php');
    ?>

     

    Explanation

    • The header.php and footer.php views are loaded statically.
    • $main_content is a dynamic variable that points to the specific view file that needs to be loaded for each page.

     

    Step 2: Create header.php in application/views/innerpages/

    The header.php file contains the common header elements of your pages, such as the <html> structure, the <head> section, and the opening <body> tag.

    File: application/views/innerpages/header.php

     

    <!DOCTYPE html>
    <html>
    <head>
    <title><?php echo $title; ?></title>
    </head>
    <body>

     

    Step 3: Create footer.php in application/views/innerpages/

    The footer.php file contains the common footer elements of your pages, including the closing tags.

    File: application/views/innerpages/footer.php

     

    <h1><?php $heading; ?></h1>
    
    </body>
    </html>

     

    Step 4: Create Welcome.php in application/controllers/

    The Welcome.php controller is responsible for loading the view files and passing data to them.

    File: application/controllers/Welcome.php

    class Welcome extends CI_Controller {
    
    	public function index() {
    		$data = [];
    		$data[‘title’] 		= ‘Page Title’;
    		$data[‘heading’]		= ‘Welcome to infovistar’
    		$data[‘main_content’]	= ‘about_us’;	// page name
    		$this->load->view(‘innerpages/template’, $data);
    	}
    }

    Explanation

    1. Loading the Template: The template.php view is loaded with the $data array, which contains the title, heading, and the main content to be displayed dynamically.
    2. Dynamic Content: The $main_content variable determines which view file to load dynamically, allowing you to switch the main content without altering the header and footer.

     

    Step 5: Create the Main Content View (about_us.php)

    Although not explicitly mentioned in the original instruction, you need a file named about_us.php to render the main content dynamically.

    File: application/views/about_us.php

    <h2>About Us</h2> 
    <p>This is the About Us section of the website.</p>

     

    Template Structure: We created a common layout using template.php to include the header, footer, and dynamic content.

    Reusability: This approach enhances code reusability by isolating common elements (header and footer) and loading the main content dynamically.

    Controller Integration: The Welcome controller demonstrates how to pass data to the template and specify which content to load.

     

    You can effectively manage your application’s layout with a clean, reusable structure in CodeIgniter 3. If you need further customization or have any questions, feel free to ask!