Commit 16280df6d10404895ffe285bc8a7e2c57fbd6fe2
1 parent
098b35d6
Линк услуги не должен ссылатся сам на себя
Showing
2 changed files
with
77 additions
and
0 deletions
Show diff stats
frontend/views/layouts/main.php
@@ -211,6 +211,8 @@ | @@ -211,6 +211,8 @@ | ||
211 | { | 211 | { |
212 | $test[$key]['label']=$item['label']; | 212 | $test[$key]['label']=$item['label']; |
213 | $test[$key]['options'] = [ 'class' => 'active' ]; | 213 | $test[$key]['options'] = [ 'class' => 'active' ]; |
214 | + $test[$key]['url']= false; | ||
215 | + | ||
214 | 216 | ||
215 | } | 217 | } |
216 | elseif( \Yii::$app->request->url=='/' && $item['label']==\Yii::t('app', 'Prices')) | 218 | elseif( \Yii::$app->request->url=='/' && $item['label']==\Yii::t('app', 'Prices')) |
@@ -230,6 +232,7 @@ | @@ -230,6 +232,7 @@ | ||
230 | 232 | ||
231 | 233 | ||
232 | ?> | 234 | ?> |
235 | + | ||
233 | <?php echo Nav::widget( | 236 | <?php echo Nav::widget( |
234 | [ | 237 | [ |
235 | 'items' => $test, | 238 | 'items' => $test, |
frontend/widgets/Nav.php
@@ -9,20 +9,94 @@ | @@ -9,20 +9,94 @@ | ||
9 | namespace frontend\widgets; | 9 | namespace frontend\widgets; |
10 | 10 | ||
11 | use yii\helpers\Html; | 11 | use yii\helpers\Html; |
12 | + use yii\helpers\ArrayHelper; | ||
13 | + | ||
12 | 14 | ||
13 | class Nav extends \yii\bootstrap\Nav | 15 | class Nav extends \yii\bootstrap\Nav |
14 | { | 16 | { |
17 | + | ||
18 | + # метод почти полностью повторяет родительский, | ||
19 | + # различия работы см.в return | ||
20 | + public function renderItem($item) | ||
21 | + { | ||
22 | + if (is_string($item)) { | ||
23 | + return $item; | ||
24 | + } | ||
25 | + if (!isset($item['label'])) { | ||
26 | + throw new InvalidConfigException("The 'label' option is required."); | ||
27 | + } | ||
28 | + $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; | ||
29 | + $label = $encodeLabel ? Html::encode($item['label']) : $item['label']; | ||
30 | + $options = ArrayHelper::getValue($item, 'options', []); | ||
31 | + $items = ArrayHelper::getValue($item, 'items'); | ||
32 | + $url = ArrayHelper::getValue($item, 'url', '#'); | ||
33 | + | ||
34 | + $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); | ||
35 | + | ||
36 | + if (isset($item['active'])) { | ||
37 | + $active = ArrayHelper::remove($item, 'active', false); | ||
38 | + } else { | ||
39 | + $active = $this->isItemActive($item); | ||
40 | + } | ||
41 | + | ||
42 | + if (empty($items)) { | ||
43 | + $items = ''; | ||
44 | + } else { | ||
45 | + $linkOptions['data-toggle'] = 'dropdown'; | ||
46 | + Html::addCssClass($options, ['widget' => 'dropdown']); | ||
47 | + Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle']); | ||
48 | + if ($this->dropDownCaret !== '') { | ||
49 | + $label .= ' ' . $this->dropDownCaret; | ||
50 | + } | ||
51 | + if (is_array($items)) { | ||
52 | + $items = $this->isChildActive($items, $active); | ||
53 | + $items = $this->renderDropdown($items, $item); | ||
54 | + } | ||
55 | + } | ||
56 | + | ||
57 | + if ($active) { | ||
58 | + Html::addCssClass($options, 'active'); | ||
59 | + } | ||
60 | + | ||
61 | + return ($url!=='')? | ||
62 | + Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options) | ||
63 | + : Html::tag('li', Html::a($label, null, $linkOptions) . $items, $options) | ||
64 | + ; | ||
65 | + } | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
15 | public function init() | 73 | public function init() |
16 | { | 74 | { |
75 | + | ||
76 | + foreach ($this->items as &$item) | ||
77 | + { | ||
78 | + if($item['url']===false)$item['url']=''; | ||
79 | + } | ||
80 | + | ||
81 | + | ||
17 | if ($this->route === null && \Yii::$app->controller !== null) { | 82 | if ($this->route === null && \Yii::$app->controller !== null) { |
18 | $this->route = \Yii::$app->controller->getRoute(); | 83 | $this->route = \Yii::$app->controller->getRoute(); |
84 | + | ||
19 | } | 85 | } |
86 | + | ||
20 | if ($this->params === null) { | 87 | if ($this->params === null) { |
21 | $this->params = \Yii::$app->request->getQueryParams(); | 88 | $this->params = \Yii::$app->request->getQueryParams(); |
89 | + | ||
22 | } | 90 | } |
91 | + | ||
23 | if ($this->dropDownCaret === null) { | 92 | if ($this->dropDownCaret === null) { |
24 | $this->dropDownCaret = '<span class="caret"></span>'; | 93 | $this->dropDownCaret = '<span class="caret"></span>'; |
94 | + | ||
25 | } | 95 | } |
96 | + | ||
97 | + | ||
98 | + | ||
26 | Html::addCssClass($this->options, []); | 99 | Html::addCssClass($this->options, []); |
100 | + | ||
27 | } | 101 | } |
28 | } | 102 | } |
29 | \ No newline at end of file | 103 | \ No newline at end of file |