[eluser]umefarooq[/eluser]
you can improve it with the following code
Code:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
Document : breadcrumbs_helper
Created on : Apr 24, 2013, 9:45:24 AM
Author : mario
Description: metodo criado para gerar breadcrumbs
*/
function simpleway($ignore_segment=array(),$list=FALSE,$attrs = array()){
/*
* Recebe o caminho do controller, dá um exeplode para trasnformar em
* array.
*/
$ignore_segment = (!is_array($ignore_segment))?array($ignore_segment):$ignore_segment;
$ci = &get;_instance();
$crumb = $ci->uri->segment_array();
$result = $ci->uri->total_segments();
/*
* coloca as primeiras letras de cada palavra em maiusculo e gera um
* link.
*/
$url_crumb = array();
foreach ($crumb as $key =>$c):
// pega o tamanho do array.
/*
* se o array for menor ou igual a 1, entende que ele está no
* controller raiz, e será linkado para o mesmo.
*/
if(!in_array($key, $ignore_segment)){
if($result<=1){
$url_crumb[] = anchor('',ucfirst($c));//'<a href="">'.ucfirst($c).'</a>';
}else{
$url_crumb[] = anchor($c,ucfirst(str_replace(array('_','-'), ' ', $c)));
}
}
endforeach;
// da um implode adicionando '>' entre as palavras.
$fim = implode(' > ',$url_crumb);
if($list)
$fim = ul($url_crumb,$attrs);
if(!empty($fim))
return 'Are you in: '.$fim;
}
?>
now you can call helper with following ways
Code:
echo simpleway(); // default out put
echo simpleway(1); // this will ignore first segment of url
echo simpleway(array(1,4)) // this will ignore first and 4th segment for crumb
echo simpleway(1,TRUE); // this will create unorder html list
echo simpleway(1,TRUE,array('class'=>'test')); // can define attributes for ul list
echo simpleway(null,TRUE,array('class'=>'test')); // this will print all segment of url in crumb