BHorizontalMenu.php
1.01 KB
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
<?php
class BHorizontalMenu extends CWidget
{
/**
* @var array
* examle:
* 'items':[{
* label:label,
* url:url|array(route,params)
* active:route_regexp||boolean
* },..]
*/
public $items;
public $class = 'nav';
public $style = "";
public function init()
{
parent::init();
}
public function run()
{
$current_route = '/' . $this->controller->module->id . '/' . $this->controller->id . '/' . $this->controller->action->id;
echo '<ul class="', $this->class, '" style="', $this->style, '">';
foreach ($this->items as $item) {
if (is_string($item['active']))
$active = (preg_match($item['active'], $current_route) > 0);
else
$active = $item['active'];
echo
'<li', ($active ? ' class="active"' : ''), '>',
CHtml::link($item['label'], $item['url']),
'</li>';
}
echo '</ul>';
}
}