Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Amit Sarker
Added: Apr 29, 2018 11:32 AM
Views: 18
Tags: no tags
  1. <?php
  2.  
  3. function generate_breadcrumb() {
  4.     $ci = &get_instance();
  5.     $i = 1;
  6.     $uri = $ci->uri->segment($i);
  7.     $link = '<nav aria-label="breadcrumb"><ol class="breadcrumb">';
  8.     while ($uri != '') {
  9.         $prep_link = '';
  10.         for ($j = 1; $j <= $i; $j++) {
  11.             $prep_link .= $ci->uri->segment($j) . '/';
  12.         }
  13.  
  14.         if ($ci->uri->segment($i + 1) == '') {
  15.             $link .= '<li class="breadcrumb-item active"><a href="' . base_url($prep_link) . '">';
  16.             $link .= ucwords(str_replace("_", " ", $ci->uri->segment($i))) . '</a></li>';
  17.         } else {
  18.             $link .= '<li class="breadcrumb-item"><a href="' . base_url($prep_link) . '">';
  19.             $link .= ucwords(str_replace("_", " ", $ci->uri->segment($i))) . '</a><span class="divider"></span></li>';
  20.         }
  21.         $i++;
  22.         $uri = $ci->uri->segment($i);
  23.     }
  24.     $link .= '</ol></nav>';
  25.     return $link;
  26. }
  27.