Breadcrumb is a navigational tool that developer often integrate in their application to give easy access to different segment of the application. This is used in applications which has multiple sequence of activities.
The following code will go into your helper file and you have to call create_breadcrumb(); function to get the formatted html text;
-
if(!function_exists(‘create_breadcrumb’)){
-
function create_breadcrumb(){
-
$ci = &get_instance();
-
$i=1;
-
$uri = $ci->uri->segment($i);
-
$link = ‘<ul>’;
-
-
while($uri != ”){
-
$prep_link = ”;
-
for($j=1; $j<=$i;$j++){
-
$prep_link .= $ci->uri->segment($j).’/';
-
}
-
-
if($ci->uri->segment($i+1) == ”){
-
$link.=’<li>» <a href="’.site_url($prep_link).’"><b>’.$ci->uri->segment($i).’</b></a></li> ’;
-
}else{
-
$link.=’<li>» <a href="’.site_url($prep_link).’">’.$ci->uri->segment($i).’</a></li> ’;
-
}
-
-
$i++;
-
$uri = $ci->uri->segment($i);
-
}
-
$link .= ‘</ul>’;
-
return $link;
-
}
-
}
-
If the current url is http://www.domain.com/user/add then the create_breadcrumb() function will return -
-
» user » ad
Here user is linked to http://www.domain.com/user/ and add is linked to http://www.domain.com/user/add
This is generated by calling in the view file. Try it out and let me know how it went
thanks,
thephpx
[ad code=1 align=center]
Hello! That’s an interesting topic but.. which helper? Can I extend it?
This is a custom helper, you need to create a custom helper file then copy the provided code. Also make sure you auto-load the required helpers before you load the custom helper.
thanks,
thephpx
how to make a dynamic breadcrumb without session and without url trap can you please help me
that is good article
Thanks!