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...


Messages In This Thread
DTE BreadCrumb Class - by El Forum - 12-16-2008, 01:06 PM
DTE BreadCrumb Class - by El Forum - 12-16-2008, 08:31 PM
DTE BreadCrumb Class - by El Forum - 12-16-2008, 08:37 PM
DTE BreadCrumb Class - by El Forum - 01-01-2009, 05:28 PM
DTE BreadCrumb Class - by El Forum - 01-01-2009, 05:48 PM
DTE BreadCrumb Class - by El Forum - 01-01-2009, 05:52 PM
DTE BreadCrumb Class - by El Forum - 01-01-2009, 07:26 PM
DTE BreadCrumb Class - by El Forum - 01-13-2009, 06:50 PM
DTE BreadCrumb Class - by El Forum - 01-13-2009, 07:17 PM
DTE BreadCrumb Class - by El Forum - 01-13-2009, 08:32 PM
DTE BreadCrumb Class - by El Forum - 01-13-2009, 09:02 PM
DTE BreadCrumb Class - by El Forum - 01-14-2009, 01:54 PM
DTE BreadCrumb Class - by El Forum - 01-14-2009, 02:02 PM
DTE BreadCrumb Class - by El Forum - 01-14-2009, 02:12 PM
DTE BreadCrumb Class - by El Forum - 01-14-2009, 02:17 PM
DTE BreadCrumb Class - by El Forum - 01-14-2009, 09:28 PM
DTE BreadCrumb Class - by El Forum - 03-03-2009, 03:45 PM
DTE BreadCrumb Class - by El Forum - 03-15-2009, 11:06 AM
DTE BreadCrumb Class - by El Forum - 04-29-2009, 07:58 PM
DTE BreadCrumb Class - by El Forum - 06-10-2009, 07:54 AM
DTE BreadCrumb Class - by El Forum - 06-11-2009, 04:33 PM
DTE BreadCrumb Class - by El Forum - 08-03-2009, 01:38 AM
DTE BreadCrumb Class - by El Forum - 09-23-2009, 02:05 PM
DTE BreadCrumb Class - by El Forum - 10-06-2009, 07:10 AM
DTE BreadCrumb Class - by El Forum - 12-21-2009, 01:21 PM
DTE BreadCrumb Class - by El Forum - 12-21-2009, 01:29 PM
DTE BreadCrumb Class - by El Forum - 12-21-2009, 01:49 PM
DTE BreadCrumb Class - by El Forum - 04-10-2010, 12:45 AM
DTE BreadCrumb Class - by El Forum - 04-10-2010, 08:22 AM
DTE BreadCrumb Class - by El Forum - 09-06-2010, 02:49 PM
DTE BreadCrumb Class - by El Forum - 09-06-2010, 04:17 PM
DTE BreadCrumb Class - by El Forum - 09-06-2010, 04:23 PM
DTE BreadCrumb Class - by El Forum - 09-06-2010, 04:29 PM
DTE BreadCrumb Class - by El Forum - 10-28-2010, 12:43 PM
DTE BreadCrumb Class - by El Forum - 06-18-2011, 05:18 PM
DTE BreadCrumb Class - by El Forum - 07-16-2012, 02:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB