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 URI Class provides methods that help you retrieve information from your URI strings. CodeIgniter 4 presents an object-oriented solution for working with URIs in your application.

Creating a URI instance:

  1. Creating a URI instance as a new class instance:
    $uri = new CodeIgniterHTTPURI();
  2. Using service() function:
    $uri = service('uri');

Simple HTML Code for Menu

<ul class="sidebar-menu" data-widget="tree">
    <li>
        <a href="<?php echo base_url("dashboard") ?>">
            <i class="fa fa-dashboard"></i> Dashboard
        </a>
    </li>
    <li class="treeview ">
	    <a href="#"> <i class="fa fa-users"></i>
            <span>Clients</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li>
                <a href="<?php echo base_url('client/add'); ?>">
                    <i class="fa fa-circle-o"></i> Add Client
                </a>
            </li>
    	    <li>
                <a href="<?php echo base_url('client/list'); ?>">
                    <i class="fa fa-circle-o"></i> List of Clients
                </a>
            </li>							
        </ul>
    </li>
</ul>

URI Segment Code for Menu

<?php 
	// Creating URI instance in View
    $uri = new CodeIgniter\HTTP\URI(current_url());
    $uri_one = '';
    if($uri->getTotalSegments() > 0 && $uri->getSegment(1))
        $uri_one = $uri->getSegment(1);
    if($uri->getTotalSegments() > 1 && $uri->getSegment(2))
	    $uri_two = $uri->getSegment(2);
    //
    // Dashboard
    $dashboard = '';
    if($uri_one == '' or $uri_one == 'dashboard') {
        $dashboard = 'class="active"';
    }
    // Client 
    $client = $client_add = $client_list = '';
    if($uri_one == "client") {
        $client = 'active';
        if($url == 'add') {
            $client_add = 'class="active"';
        } if($url == 'list') {
            $client_list = 'class="active"';
        }
    }
?>

Example:

<?php 
// Creating URI instance in View
    $uri = new CodeIgniter\HTTP\URI(current_url());
    $uri_one = '';
    if($uri->getTotalSegments() > 0 && $uri->getSegment(1))
        $uri_one = $uri->getSegment(1);
    if($uri->getTotalSegments() > 1 && $uri->getSegment(2))
	    $uri_two = $uri->getSegment(2);
    //
    // Dashboard
    $dashboard = '';
    if($uri_one == '' or $uri_one == 'dashboard') {
        $dashboard = 'class="active"';
    }
    // Client 
    $client = $client_add = $client_list = '';
    if($uri_one == "client") {
        $client = 'active';
        if($url == 'add') {
            $client_add = 'class="active"';
        } if($url == 'list') {
            $client_list = 'class="active"';
        }
    }
?>
    
<ul class="sidebar-menu" data-widget="tree">
    <li>
        <a href="<?php echo base_url("dashboard") ?>">
            <i class="fa fa-dashboard"></i> Dashboard
        </a>
    </li>
    <li class="treeview ">
	    <a href="#"> <i class="fa fa-users"></i>
            <span>Clients</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li>
                <a href="<?php echo base_url('client/add'); ?>">
                    <i class="fa fa-circle-o"></i> Add Client
                </a>
            </li>
    	    <li>
                <a href="<?php echo base_url('client/list'); ?>">
                    <i class="fa fa-circle-o"></i> List of Clients
                </a>
            </li>							
        </ul>
    </li>
</ul>

Output:

 Highlight Menu using URI Segment