Welcome Guest, Not a member yet? Register   Sign In
DTE BreadCrumb Class
#1

[eluser]ericsodt[/eluser]

I decided to create a bread crumb class after doing some searching on the web and through this forum. There were a couple attempts at making something, but it was dependent on uri segments, which was not going to work for me. I created this class using CI 1.7 and PHP 5. If you're working with PHP4 and would like to make it backwards compatible, please feel free to do so. Hopefully you guys find it as useful as I have.



Please let me know what you think.



Download my BreadCrumb Library here: DTE-BreadCrumbs version 1.8



Differences between 1.7 and 1.8:
1.7 - Was serializing and un-serializing the breadcrumb data.
1.8 - I removed this serialization/un-serialization code which should speed up processing and decrease load time.



Inside the zip you'll see the 'application' folder, underneath that you'll find the 'libraries', 'contollers', 'view' and 'config' folders. Take the classes and put them in their respective directories within CI. (except for config.php, just add the lines of code contained within that file into your existing config.php) The controller class below is the one in which you'll find within the zip file.



Controllers Folder:



Controller Class (in this case, I named my controller 'Home')
Code:
<?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();    
    }
    
    function index(){
        
        // setup breadcrumb
        $bc = array(
               'title' => 'Home',
               'url' => 'home',
               'isRoot' => true
        );        
        $this->breadcrumb->setBreadCrumb($bc);
        
        // pass data onto the views
        $data = array(
               'title' => 'my name',
               'content' => 'home',
               'breadcrumbs'=>get_Instance()->breadcrumblist->display()
        );
        $this->load->view('siteLayout',$data);
    }


    function test(){    
        $bc = array(
               'title' => 'Test',
               'url' => 'home/test',
               'isRoot' => false
        );        
        $this->breadcrumb->setBreadCrumb($bc);
                
        $data = array(
               'title' => 'my name',
               'content' => 'home',
               'breadcrumbs'=>get_Instance()->breadcrumblist->display()
        );


        $this->load->view('siteLayout',$data);
    }    
    
    
    function test2(){    
        $bc = array(
               'title' => 'Test 2',
               'url' => 'home/test2',
               'isRoot' => false
        );
        $this->breadcrumb->setBreadCrumb($bc);
        
        $data = array(
               'title' => 'my name',
               'content' => 'home',
               'breadcrumbs'=>get_Instance()->breadcrumblist->display()
        );

        $this->load->view('siteLayout',$data);
    }        
}

ONLY ADD THIS ONE INDEX, DONT OVERWRITE YOUR CONFIG FILE WITH THE ONE I SUPPLY. I ONLY SUPPLY IT AS AN EXAMPLE, SO YOU CAN CUT AND PASTE IT. AGAIN D-O-N-T OVERWRITE YOUR CONFIG FILE WITH THE ONE I SUPPLY

Config.php (add this to your existing config file)
Code:
/*
|--------------------------------------------------------------------------
| BreadCrumb Delimiter
|--------------------------------------------------------------------------
|
| If left blank will be the arrow, otherwise it will default to what you
| set here
|
*/
$config['breadcrumbDelimeter'] = "»";



As you can see, within each method we pass in an array to my auto-loaded BreadCrumb Class (I also autoload my BreadCrumbList class and url class as well). This array adheres to the BreadCrumb classes mutators (setters/getters). For the case of BreadCrumb we have get/set: title, url and isRoot. The first two are self explanatory. The 'isRoot' property tells the BreadCrumb if it should start at the beginning, removing the bread crumb chain. Essentially starting the bread crumb chaining process again, from start; like when switching modules.



Now to display the bread crumbs within your view, do the following:

Code:
...
    <td>
        <br>
           <span style="padding-left: 5px">
              &lt;?php if(isset($breadcrumbs)): ?&gt;
                 &lt;?=$breadcrumbs?&gt;
              &lt;?php endif;?&gt;
       </span>
        </br>
    </td>
...


This is my first shot at creating a CI/PHP library so be kind and use often. Please leave feedback.
I hope this class helps the many of you that were as frustrated as I was with the lack of a BreadCrumb class within CI.



If you do decide to use it on your site, please let me know either by email or posting here. I am trying to get this into the next version of CI, but before I can do that it needs to be community tested first. Thx



[EDIT:]
Issue has been fixed as of 12/17/08. The issue was caused by CI's session class not being able to hold the array's serialized data. I had to switch from $this->session to $_SESSION. Works on both windows and unix. You can view the demo on my site.

[EDIT:]
After creating and testing on a Windows environment, I placed it up on my host company's server (unix) and now it isnt working... I'll start bebugging and will post when working correctly...
#2

[eluser]PowerCode[/eluser]
The download link seems to be down.
#3

[eluser]ericsodt[/eluser]
[quote author="PowerCode" date="1229502677"]The download link seems to be down.[/quote]

Thank you for letting me know... link is now fixed!
#4

[eluser]Mateo1041[/eluser]
Thanks for posting this. However, it doesn't work for me with CI 1.7:

Code:
An Error Was Encountered

Unable to load the requested class: breadcrumb

Code:
function index()
    {
        $this->load->library('BreadCrumb');
        $this->load->library('Breadcrumblist');
      $bc = array('title' => 'Test', 'url' => 'home/test', 'isRoot' => false);        
        $this->breadcrumb->setBreadCrumb($bc);
        $data = array('title' => 'Dean T. Ericson', 'content' => 'home', 'breadcrumbs'=>get_Instance()->breadcrumblist->display());
        $this->load->view('home', $data);
    }

Is there another way in which to load the class?
#5

[eluser]ericsodt[/eluser]
[quote author="Mateo1041" date="1230874091"]
Is there another way in which to load the class?
[/quote]

I load mine through the configuration files

Autoload.php
Code:
...
$autoload['libraries'] = array('session','breadcrumb','breadcrumblist');
...
#6

[eluser]ericsodt[/eluser]
[quote author="Mateo1041" date="1230874091"]Thanks for posting this. However, it doesn't work for me with CI 1.7:

Code:
An Error Was Encountered

Unable to load the requested class: breadcrumb

Code:
function index()
    {
        $this->load->library('BreadCrumb');
        $this->load->library('Breadcrumblist');
      $bc = array('title' => 'Test', 'url' => 'home/test', 'isRoot' => false);        
        $this->breadcrumb->setBreadCrumb($bc);
        $data = array('title' => 'Dean T. Ericson', 'content' => 'home', 'breadcrumbs'=>get_Instance()->breadcrumblist->display());
        $this->load->view('home', $data);
    }

Is there another way in which to load the class?[/quote]



I created the classes using the CI standard so to load the class you have to do the following on your end... (Lowercase class name)

Code:
$this->load->library('breadcrumb');
$this->load->library('breadcrumblist');

Hope that helps!
#7

[eluser]Mateo1041[/eluser]
Thanks! It worked. I had been going by what the documentation said about how case shouldn't matter when loading a library class. I also saw your template link in your signature and appreciate the info.
#8

[eluser]morozgrafix[/eluser]
I think you should mention that URL Helper should also be loaded. anchor() funciton in Breadcrumblist.php (line 100) depends on it.

Thanks.
#9

[eluser]ericsodt[/eluser]
[quote author="morozgrafix" date="1231915823"]I think you should mention that URL Helper should also be loaded. anchor() funciton in Breadcrumblist.php (line 100) depends on it.

Thanks.[/quote]

Good point! I believe CI comes with it already loaded by default... In any case, yes, I have the url class loaded in my autoload config file

Code:
/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|    $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('url');
#10

[eluser]morozgrafix[/eluser]
Thank you for creating this class. I just added it to my project and it works great.
Sorry can't give you URL for the site since this is intranet portal site.

One thing to add (and I haven't played much with DTE BreadCrumb Class yet) is ability to specify configurable option for breadcrumb delimiter.

For example one would like to use "&gt;" as delimiter for some parts of the project and then use "&raquo;" or "&rarr;" somewhere else.

I've hardcoded it for my project to this on line 34 of Breadcrumb.php for now:

Code:
$CI->breadcrumblist->setDelimeter(' &raquo; ');

I've checked and URL helper is not loaded by default in CI 1.7. My vanilla autoload.php shows this:

Code:
/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|    $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array();




Theme © iAndrew 2016 - Forum software by © MyBB