CodeIgniter Forums
I thought i would give back and share my breadcrumb / crumbtrail helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: I thought i would give back and share my breadcrumb / crumbtrail helper (/showthread.php?tid=27749)



I thought i would give back and share my breadcrumb / crumbtrail helper - El Forum - 02-19-2010

[eluser]Unknown[/eluser]
Well here goes :

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('breadcrumb'))
{
    function breadcrumb($pages, $separator = '', $endlink = FALSE)
    {
        $depth = count($pages);

        $i = 0;
        
        $output = '<ul id="breadcrumb">';

        foreach ($pages as  $url => $label)
        {
             $i++;

             if($depth > $i)
             {
                $output .= '<li>'.anchor($url, $label).'</li>';

                if($separator != '')
                {
                    $output .= '<li class="separator">'.$separator.'</li>';
                }
             }

             else
             {
                 if($depth == $i && $endlink == TRUE)
                 {
                    $output .= '<li>'.anchor($url, $label).'</li>';

                 }

                 else
                 {
                    $output .= '<li><span>'.$label.'</span></li>';
                 }
             }
        }
      
        $output .= '</ul>';

        return $output;
    }
}

You can use it by feeding it a Key/Value (URL / Label) array from your controller :
Code:
$data->crumbs['my/url'] = 'label';
$data->crumbs['my/other/url'] = 'otherLabel';

and call it in your view with
Quote:&lt;?php echo breadcrumb($crumbs); ?&gt;

Optional paramaters are 'separator' to chose the separator symbol and 'endlink' to determin wether the last element is a link or not