Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1065633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:50:17+00:00 2026-05-16T19:50:17+00:00

What would be the best way to check for the current URI segment in

  • 0

What would be the best way to check for the current URI segment in a CodeIgniter view? What I am trying to do is use the current URI segment [i.e. $this->uri->segment(1)] in order to highlight the current page on the navigation bar.

The best that I have figured out is to do

$data['current_uri'] = $this->uri->segment(1);
$this->load->view('header', $data);

in each of my controllers and then in the header.php file, I check the $current_uri variable to determine which part of the navigation should be highlighted. As you know, this is a very tedious way of doing it, but I’m at a loss of a better way to do this.

It may even be possible to extend the default Controller class to pass the current URI segment, but I’m not sure if this would work, or even how to go about doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:50:19+00:00Added an answer on May 16, 2026 at 7:50 pm

    I myself use an extra function similar to anchor(). I call it active_anchor(), and it takes all the same parameters plus another (the uri). The function then adds the class ‘active’ if the uri string passed matches the active_anchor() url paramter.

    Then the function returns using the anchor function (all that the function did was determine if the link needed the class ‘active’ or not.

    EDIT:

    I just put this code in a file called ‘MY_url_helper.php’. That way, when the url helper is loaded (I actually auto load that one since pretty much all of my views use it anyway.) This is just some quick code too, pretty sure it would work. Basically it takes the same arguments as the anchor() function, but also the $key variable. It appends a class of “active” to the anchor tag if the key and url match.

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    if ( ! function_exists('active_anchor'))
    {
        function active_anchor($url = NULL, $title = NULL, $key = NULL, $params = array())
        {
            if ($url && $key)
            {
                if($key == $url)
                {
                    if (array_key_exists ('class' , $params))
                    {
                        $params['class'] .= ' active';
                    }
                    else
                    {
                        $params['class'] = 'active';
                    }
                }
            }
            return anchor($url, $title, $params);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would
What's the best way, using SQL, to check the maximum number of connections that
I would like to indicate the currently chosen page in a shared menu component
Let's say you have a profile page that can only be accessed by the
I am building a search page in asp.net 3.5. Search takes a bit of
I need to create a checklist using a UITableView with the accessoryView as a
I want to write a class library that works in ASP.NET and standalone applications.
I am currently working on converting an application from access to C# and have
Currently i have an application that reads and writes several properties from one or
I have been working with PHP for years and gotten a very good grasp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.