1 <?php
2 3 4 5 6 7 8
9
10 Yii::import('zii.widgets.CBreadcrumbs');
11
12 13 14 15
16 class TbBreadcrumbs extends CBreadcrumbs
17 {
18 19 20
21 public $separator = '/';
22
23 24 25
26 public function init()
27 {
28 if (isset($this->htmlOptions['class']))
29 $this->htmlOptions['class'] .= ' breadcrumb';
30 else
31 $this->htmlOptions['class'] = 'breadcrumb';
32 }
33
34 35 36 37
38 public function run()
39 {
40
41 if (empty($this->links))
42 return;
43
44 $links = array();
45
46 if (!isset($this->homeLink))
47 {
48 $content = CHtml::link(Yii::t('zii', 'Home'), Yii::app()->homeUrl);
49 $links[] = $this->renderItem($content);
50 }
51 else if ($this->homeLink !== false)
52 $links[] = $this->renderItem($this->homeLink);
53
54 foreach ($this->links as $label => $url)
55 {
56 if (is_string($label) || is_array($url))
57 {
58 $content = CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url);
59 $links[] = $this->renderItem($content);
60 }
61 else
62 $links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
63 }
64
65 echo CHtml::tag('ul', $this->htmlOptions, implode('', $links));
66 }
67
68 69 70 71 72 73
74 protected function renderItem($content, $active = false)
75 {
76 $separator = !$active ? '<span class="divider">'.$this->separator.'</span>' : '';
77
78 ob_start();
79 echo CHtml::openTag('li', $active ? array('class'=>'active') : array());
80 echo $content.$separator;
81 echo '</li>';
82 return ob_get_clean();
83 }
84 }
85