From 0c7545c276a0f281a2989798dabe3676db9956cf Mon Sep 17 00:00:00 2001 From: callmez Date: Wed, 14 Aug 2013 10:15:08 +0800 Subject: [PATCH] Make DropDown support divider class. ```php Dropdown::widget(array( 'items' => array( array('label' => 'li1', 'url' => $this->context->createUrl('site/index')), array('label' => '', 'options' => array('class' => 'divider')), array('label' => 'li3', 'url' => $this->context->createUrl('site/index')), ) ) ``` --- framework/yii/bootstrap/Dropdown.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/framework/yii/bootstrap/Dropdown.php b/framework/yii/bootstrap/Dropdown.php index 0568fe40ecd..5c3973563e8 100644 --- a/framework/yii/bootstrap/Dropdown.php +++ b/framework/yii/bootstrap/Dropdown.php @@ -75,16 +75,20 @@ protected function renderItems($items) if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } - $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); - $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); - $linkOptions['tabindex'] = '-1'; - - if (isset($item['items'])) { - Html::addCssClass($options, 'dropdown-submenu'); - $content = Html::a($label, '#', $linkOptions) . $this->renderItems($item['items']); + if (empty($item['label'])) { + $content = ''; } else { - $content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions); + $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; + $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); + $linkOptions['tabindex'] = '-1'; + + if (isset($item['items'])) { + Html::addCssClass($options, 'dropdown-submenu'); + $content = Html::a($label, '#', $linkOptions) . $this->renderItems($item['items']); + } else { + $content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions); + } } $lines[] = Html::tag('li', $content, $options); }