Create Breadcrumb In PHP

Simple way to create breadcrumb in php or codeigniter framework. It is very important thing to navigate using breadcrumb when we exist inner pages.

In this tutorial you will get idea how to develop your own breadcrumb with dynamic url generation in codeigniter. You have to just write simple function in your util_helper.php which is available in your helper folder inside app folder. If file is not available there then you can create one file like my_util_helper.php and write function over-there  like generateBreadcrumb().

So follow this code for breadcrumb creation :

function generateBreadcrumb(){
  $ci = &get_instance();
  $uri = $ci->uri->segment($i);
  $link = '
  <div class="pageheader">
      <h2><i class="fa fa-edit"></i>'.$ci->uri->segment($i).'</h2>
      <div class="breadcrumb-wrapper">

  <ol class="breadcrumb">';

  while($uri != ''){
    $prep_link = '';
  for($j=1; $j<=$i;$j++){
    $prep_link .= $ci->uri->segment($j).'/';

  if($ci->uri->segment($i+1) == ''){
    $link.='<li class="active"><a href="'.site_url($prep_link).'">';
    $link.=$ci->uri->segment($i).'</a></li> ';
    $link.='<li><a href="'.site_url($prep_link).'">';
    $link.=$ci->uri->segment($i).'</a><span class="divider"></span></li> ';

  $uri = $ci->uri->segment($i);
    $link .= '</ol></div></div>';
    return $link;

After creation of function you have to echo this function your header or where you want this breadcrumb like this
//your html code goes here and where you want just paste it below script.
 echo generateBreadcrumb();
you have to adjust css according your template style or css. you will see result of this function look like this image. Untitled 

Thank You....
  • Huy NV

    how can I send it to view. I got this error Severity: Notice
    Message: Array to string conversion….Any help would be highly appreciated!!!!

  • Huy NV

    Hi again!
    This morning I’ve just checked it again and finally I got an error and need kind guy to help me out.Thanks for any advice…Hereunder my error was showed
    Message: Only variables should be passed by reference
    Filename: libraries/breadcrumbs.php
    Line Number: 74