Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Commit fa24227

Browse files
committed
Add library and config files
1 parent 2d86b00 commit fa24227

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CodeIgniter-Layout
2+
3+
CodeIgniter-Breadcrumb is a library that helps your build HTML breadcrumbs with CodeIgniter.
4+
5+
6+
## Requirements
7+
8+
1. PHP 5.1+
9+
2. CodeIgniter 1.6.x - 2.0-dev

config/breadcrumb.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
/*
3+
| -------------------------------------------------------------------
4+
| BREADCRUMB CONFIG
5+
| -------------------------------------------------------------------
6+
| This file will contain the settings needed to load the breadbrumb.
7+
|
8+
| -------------------------------------------------------------------
9+
| EXPLANATION OF VARIABLES
10+
| -------------------------------------------------------------------
11+
|
12+
| ['divider'] The string used to divide the crumbs
13+
| ['tag_open'] The opening tag placed on the left side of the breadcrumb.
14+
| ['tag_close'] The closing tag placed on the right side of the breadcrumb.
15+
|
16+
*/
17+
18+
19+
/* End of file breadcrumb.php */
20+
/* Location: ./application/config/breadcrumb.php */

libraries/Breadcrumb.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
/**
3+
* Breadcrumb Class
4+
*
5+
* This class manages the breadcrumb object
6+
*
7+
* @author Richard Davey <info@richarddavey.com>
8+
* @copyright Copyright (c) 2011, Richard Davey
9+
* @package CodeIgniter
10+
* @subpackage Libraries
11+
* @link https://github.com/richarddavey/codeigniter-breadcrumb
12+
*/
13+
class Breadcrumb {
14+
15+
/**
16+
* Breadcrumbs stack
17+
*
18+
*/
19+
private $breadcrumbs = array();
20+
21+
/**
22+
* Options
23+
*
24+
*/
25+
private $divider = '&nbsp;&#8250;&nbsp;';
26+
private $tag_open = '<div id="breadcrumb">';
27+
private $tag_close = '</div>';
28+
29+
/**
30+
* Constructor
31+
*
32+
* @access public
33+
* @param array initialization parameters
34+
*/
35+
public function __construct($params = array())
36+
{
37+
if (count($params) > 0)
38+
{
39+
$this->initialize($params);
40+
}
41+
42+
log_message('debug', "Breadcrumb Class Initialized");
43+
}
44+
45+
// --------------------------------------------------------------------
46+
47+
/**
48+
* Initialize Preferences
49+
*
50+
* @access public
51+
* @param array initialization parameters
52+
* @return void
53+
*/
54+
private function initialize($params = array())
55+
{
56+
if (count($params) > 0)
57+
{
58+
foreach ($params as $key => $val)
59+
{
60+
if (in_array($key, array('divider', 'tag_open', 'tag_close')) AND isset($this->$key))
61+
{
62+
$this->$key = $val;
63+
}
64+
}
65+
}
66+
}
67+
68+
// --------------------------------------------------------------------
69+
70+
/**
71+
* Append crumb to stack
72+
*
73+
* @access public
74+
* @param string $title
75+
* @param string $href
76+
* @return void
77+
*/
78+
function append_crumb($title, $href)
79+
{
80+
// no title or href provided
81+
if (!$title OR !$href) return;
82+
83+
// add to end
84+
$this->breadcrumbs[] = array('title' => $title, 'href' => $href);
85+
}
86+
87+
// --------------------------------------------------------------------
88+
89+
/**
90+
* Prepend crumb to stack
91+
*
92+
* @access public
93+
* @param string $title
94+
* @param string $href
95+
* @return void
96+
*/
97+
function prepend_crumb($title, $href)
98+
{
99+
// no title or href provided
100+
if (!$title OR !$href) return;
101+
102+
// add to start
103+
array_unshift($this->breadcrumbs, array('title' => $title, 'href' => $href));
104+
}
105+
106+
// --------------------------------------------------------------------
107+
108+
/**
109+
* Generate breadcrumb
110+
*
111+
* @access public
112+
* @return string
113+
*/
114+
function output()
115+
{
116+
// breadcrumb found
117+
if ($this->breadcrumbs) {
118+
119+
// set output variable
120+
$output = $this->tag_open;
121+
122+
// add html to output
123+
foreach ($this->breadcrumbs as $key => $crumb) {
124+
125+
// add divider
126+
$output .= $this->divider;
127+
128+
// if last element
129+
if (end(array_keys($this->breadcrumbs)) == $key) {
130+
$output .= '<span>' . $crumb['title'] . '</span>';
131+
132+
// else add link and divider
133+
} else {
134+
$output .= '<a href="' . $crumb['href'] . '">' . $crumb['title'] . '</a>';
135+
}
136+
}
137+
138+
// return html
139+
return $output . $this->tag_close . PHP_EOL;
140+
}
141+
142+
// return blank string
143+
return '';
144+
}
145+
146+
}
147+
// END Breadcrumb Class
148+
149+
/* End of file Breadcrumb.php */
150+
/* Location: ./application/libraries/Breadcrumb.php */

0 commit comments

Comments
 (0)