Welcome Guest, Not a member yet? Register   Sign In
I thought i would give back and share my breadcrumb / crumbtrail helper
#1

[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




Theme © iAndrew 2016 - Forum software by © MyBB