-
Notifications
You must be signed in to change notification settings - Fork 33
/
EBootstrapBreadcrumbs.php
74 lines (59 loc) · 1.66 KB
/
EBootstrapBreadcrumbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
Yii::import('zii.widgets.CBreadcrumbs');
/**
* Wrapper class for CBreadcrumbs
* Apply bootstrap style to the breadcrumbs
*
* @author Tim Helfensdörfer <[email protected]>
* @version 0.3.9
* @package bootstrap.yiiwidgets
*/
class EBootstrapBreadcrumbs extends CBreadcrumbs {
/**
* Separator for the items.
* In Bootstrap 3 seperators are added automatically.
*/
public $separator = '';
/**
* Init the widget
*/
public function init() {
parent::init();
EBootstrap::mergeClass($this->htmlOptions, array('breadcrumb'));
}
/**
* Render the breadcrumbs
*/
public function run() {
if(empty($this->links))
return;
echo EBootstrap::openTag('ul', $this->htmlOptions)."\n";
$links=array();
if($this->homeLink===null)
$links[]=EBootstrap::openTag('li').EBootstrap::link(Yii::t('zii','Home'),Yii::app()->homeUrl);
else if($this->homeLink!==false)
$links[]=EBootstrap::openTag('li').$this->homeLink;
$count = count($this->links);
if ($count > 0) {
$links[] = $this->separator.EBootstrap::closeTag('li')."\n";
$i = 0;
foreach($this->links as $label=>$url) {
$i++;
if(is_string($label) || is_array($url))
$links[]=EBootstrap::openTag('li').EBootstrap::link($this->encodeLabel ? EBootstrap::encode($label) : $label, $url);
else
$links[]=EBootstrap::openTag('li').'<span>'.($this->encodeLabel ? EBootstrap::encode($url) : $url).'</span>';
if ($i < $count) {
$links[] = $this->separator;
}
$links[] = EBootstrap::closeTag('li')."\n";
}
}
else {
$links[] = EBootstrap::closeTag('li')."\n";
}
echo implode($links);
echo EBootstrap::closeTag('ul');
}
}
?>