1: <?php
2: /**
3: * TbBreadcrumbs class file.
4: * @author Christoffer Niska <[email protected]>
5: * @copyright Copyright © Christoffer Niska 2013-
6: * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7: */
8:
9: Yii::import('bootstrap.helpers.TbHtml');
10:
11: /**
12: * Bootstrap breadcrumb widget.
13: * @see http://twitter.github.com/bootstrap/components.html#breadcrumbs
14: * @package bootstrap.widgets
15: */
16: class TbBreadcrumb extends CWidget
17: {
18: /**
19: * @var string the divider between links in the breadcrumbs.
20: */
21: public $divider = '/';
22: /**
23: * @var boolean whether to HTML encode the link labels.
24: */
25: public $encodeLabel = true;
26: /**
27: * @var string the label for the first link in the breadcrumb.
28: */
29: public $homeLabel;
30: /**
31: * @var array the url for the first link in the breadcrumb
32: */
33: public $homeUrl;
34: /**
35: * @var array the HTML attributes for the breadcrumbs.
36: */
37: public $htmlOptions = array();
38: /**
39: * @var array list of links to appear in the breadcrumbs.
40: */
41: public $links = array();
42:
43: /**
44: * Initializes the widget.
45: */
46: public function init()
47: {
48: $this->htmlOptions['divider'] = $this->divider;
49: }
50:
51: /**
52: * Runs the widget.
53: */
54: public function run()
55: {
56: // todo: consider adding control property for displaying breadcrumbs even when empty.
57: if (!empty($this->links)) {
58: $links = array();
59: if ($this->homeLabel !== false) {
60: $label = $this->homeLabel !== null ? $this->homeLabel : TbHtml::icon('home');
61: $links[$label] = $this->homeUrl !== null ? $this->homeUrl : Yii::app()->homeUrl;
62: }
63: foreach ($this->links as $label => $url) {
64: if (is_string($label)) {
65: if ($this->encodeLabel) {
66: $label = CHtml::encode($label);
67: }
68: $links[$label] = $url;
69: } else {
70: $links[] = $this->encodeLabel ? CHtml::encode($url) : $url;
71: }
72: }
73: echo TbHtml::breadcrumbs($links, $this->htmlOptions);
74: }
75: }
76: }
77: