Welcome Guest, Not a member yet? Register   Sign In
Code Igniter Breadcrumbs
#1

[eluser]Spaxx[/eluser]
Hi.
Is there a library for creating menu breadcrumbs in code igniter?
#2

[eluser]Lone[/eluser]
No there isn't as it is very specific to how you build your application. The closest thing you could look at using is the URI class functions but that is only useful if your breadcrumb trail was relative to your URL.
#3

[eluser]esra[/eluser]
[quote author="Spaxx" date="1208979404"]Hi.
Is there a library for creating menu breadcrumbs in code igniter?[/quote]

Holger Lampe submitted a breadcrumb class long ago which was later optimized for PHP5 (two versions in the same file distribution). I'm not sure if it still works with 1.6.x, but it did work with 1.5.x.

http://ellislab.com/forums/viewthread/46408/
#4

[eluser]HdotNET[/eluser]
quick and dirty... php4/5, doesn't even need code igniter. to install just drop into libraries and load it.

Edit: copy from here: breadcrumb.php

Code:
<?php
class Breadcrumb{
    var $bread = '';
    var $crumbs = array();
    var $href_param;
    var $seperator;
    var $home_text;
    var $home_link;
    function Breadcrumb($seperator=" > ",$href_param=NULL,$home_link='/',$home_text = "Home"){
        $this->href_param = $href_param;
        $this->seperator = $seperator;    
        $this->home_text = $home_text;
        $this->home_link = $home_link;
        $this->crumbs[] = array('crumb'=>$this->home_text,'link'=>$this->home_link);
    }
    function addCrumb($this_crumb,$this_link = NULL){
        $in_crumbs = false;
        // first check that we haven't already got this link in the breadcrumb list.
        foreach($this->crumbs as $crumb){
            if($crumb['crumb'] == $this_crumb ){
                $in_crumbs = true;
            }
            if($crumb['link'] == $this_link &&  $this_link != ''){
                $in_crumbs = true;
            }
        }
        if($in_crumbs == false){
            $this->crumbs[] = array('crumb'=>$this_crumb,'link'=>$this_link);
        }
    }
    // call this to return your breadcrumb html
    function makeBread(){
        $sandwich = $this->crumbs;
        $slices = array();
        foreach($sandwich as $slice){
            if (isset($slice['link']) && $slice['link'] != '') {
                $slices[] = '<a href="' . $slice['link'] . '" '.$this->href_param.'>' . $slice['crumb'] . '</a>';
            } else {
                $slices[] = $slice['crumb'];
            }    
        }
        $this->bread = join($this->seperator, $slices);
        return $this->bread;
    }
}
?&gt;
#5

[eluser]Spaxx[/eluser]
Thanx Guyz.
#6

[eluser]alan42[/eluser]
ok... i'm a noob to this. i dropped this into my libraries and it *sort of* works. I'm thinking i'm not calling the functions properly. Throughout the entire site I only get 2 levels of breadcrumbs, ie:

Home > Page

If I go deeper into the site then 'Page' gets replaced with the current page. What I'd like to get is:

Home > Page 1 > Page 2


any suggestions?


thanks.
#7

[eluser]HdotNET[/eluser]
alan42 >> which breadcrumb class are you using?

mine or Spaxx's?

if mine... please supply some code as to how you are using it.
#8

[eluser]alan42[/eluser]
I'm using your code from a few posts back. Here's basically how i'm using it:

$this->breadcrumb->addCrumb($carrier);
$data['crumbs'] = $this->breadcrumb->makeBread();

I load the library into every controller i'm using it in (i know that sounds like it should be understood but i don't like taking things for granted, ya know?). I then pass $data onto whatever view.

The only place i don't use makeBread() is on the main page of the site. In that case, the controller only has this:

$this->breadcrumb->addCrumb('main');

I don't use makeBread() in that controller.

I hope that helps clear up where I am.

Many thanks.
#9

[eluser]HdotNET[/eluser]
alan42..

Are you expecting this breadcrumb class to remember where you have been between page requests?

Because it won't. Its for building up a breadcrumb from a single page request only, with each crumb in the trail being generated by the controller handling the request at the time.
#10

[eluser]alan42[/eluser]
i was hoping it would do that. i guess i would need to add however many crumbs i want in the controller before i call makeBread. it's sort of faking it but i think that would do the trick. do you have any other suggestions?




Theme © iAndrew 2016 - Forum software by © MyBB