Codeigniter: Helper – Create breadcrumb from url

Breadcrumb is a navigational tool that developer often integrate in their application to give easy access to different segment of the application. This is used in applications which has multiple sequence of activities.

The following code will go into your helper file and you have to call create_breadcrumb(); function to get the formatted html text.

If the current url is http://www.domain.com/user/add then the create_breadcrumb() function will return -

Here user is linked to http://www.domain.com/user/ and add is linked to http://www.domain.com/user/add

This is generated by calling in the view file. Try it out and let me know how it went.

This entry was posted in codeigniter and tagged , . Bookmark the permalink.

4 Responses to Codeigniter: Helper – Create breadcrumb from url

  1. mawan says:

    hi sir,, can u give pls a sample source code ?

    • thephpx says:

      Hi Mawan,

      The code is already given in the post just copy it to any new codeigniter helper file and then load it then you will be able to use the code as is.

      thanks,

      faisal ahmed

  2. Steve says:

    Thanks, gonna use your helper!

  3. I just removed the ul wrapper and changed it to my like so its easier for me to use the way I wanted.


    function create_breadcrumb($sep = ' > ') {
    $ci = &get_instance();
    $i = 1;
    $uri = $ci->uri->segment($i);
    $link = '';

    while ($uri != '') {
    $prep_link = '';
    for ($j = 1; $j uri->segment($j) . '/';
    }

    if ($ci->uri->segment($i + 1) == '') {
    $link.='';
    $link.=$ci->uri->segment($i) . '
    ';
    } else {
    $link.='';
    $link.=$ci->uri->segment($i) . '
    > ';
    }
    $i++;
    $uri = $ci->uri->segment($i);
    }
    return $link;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>