Friday, November 13
Trending
- Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know
- Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe
- 10 Best DDoS Protection Services for 2027
- 12 Best Web Application Firewalls (WAF) for 2027
- Best Ethical Hacking Tools in 2027: Free & Paid Picks
- Software supply chain attacks 2026: Timeline and developer checklist
- Binance Hack: $6.3 Billion Drained in the Largest Crypto Theft Ever. What We Know So Far
- This Site Uses XSLT Chrome Warning Explained: How to Fix It
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:
- Creating a URI instance as a new class instance:
$uri = new CodeIgniterHTTPURI();
- 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:




