Yii 1.1.21:是否可以在同一个按钮组中创建两个下拉按钮?

Yii 1.1.21 : is it possible to create two dropdown buttons in the same button group?

我是 Yii 的新手,我一直在寻找关于 Yii 和 CMenu 的文档。我使用过 Phalcon 和其他各种具有类似选项的框架,但是 Yii 的菜单引擎是对我来说是新的。

我正在尝试创建一个带有两个下拉菜单按钮的按钮菜单,每个按钮都有子菜单项,如下所示: Drop Down Button Group

但是 Yii CMenu 引擎呈现的是两个相互重叠的下拉菜单,并且都由相同的按钮触发。像这样: enter image description here

查看呈现的代码,看起来两个下拉菜单被 CMenu 分配了 "dropdown-menu" class(或任何 bootstrap 启用的库),因为它们在同一个按钮组中,当分配 "open" class 时,它会同时打开两个下拉菜单。

所以我的问题很简单,甚至可以使用 CMenu 菜单数组在同一个菜单中包含两个下拉菜单。是否有菜单 "Item Option" 或 "HTML Option" 我可以添加到菜单项属性,所有这些都将引用两个不同的 css 标签?我知道我一定错过了什么。

以下是在视图中构建菜单的方式。

$this->menu = array_merge($this->menu, array(
      array(
          'label' => '<span class="hidden-xs hidden-sm">' . Yii::t('app', 'Export') . '</span>',
          'encodeLabel' => false,
          'htmlOptions' => array('id' => 'export-or-email-btn', 'class' => 'navbar-btn btn-sm',),
          'items' => array(
              array(
                  'label' => Yii::t('app', 'Export'),
                  'icon' => 'fa fa-file-excel-o',
                  'visible' => true,
                  'itemOptions' => array('class' => 'work-order-export-btn'),
              ),
              array(
                  'label' => Yii::t('app', 'Email Export'),
                  'icon' => 'fa fa-envelope-o',
                  'visible' => true,
                  'itemOptions' => array('id' => $model->getClassName(), 'class' => 'email-export-btn', 'data-grid-id' => 'work-order-grid'),
              ),
              array(
                  'label' => Yii::t('app', 'Export as Import Template'),
                  'icon' => 'fa fa-file-excel-o fa-lg',
                  'visible' => true,
                  'itemOptions' => array('class' => 'work-order-export-import-btn'),
              ),),),);

$this->menu = array_merge($this->menu, array(
    array(
        'label' => '<span class="hidden-xs hidden-sm">' . Yii::t('app', 'Actions') . '</span>',
        'encodeLabel' => false,
        'htmlOptions' => array(
            'id' => 'work-order-actions-btn work-order-actions',
            'class' => 'navbar-btn btn-sm',
            'style' => 'margin: 0 0 0 15px;',
        ),
        'items' => array(
            array(
                'icon' => 'fa fa-print fa-lg',
                'label' => Yii::t('app', 'Print to PDF'),
                'visible' => true,
                'itemOptions' => array(
                    'class' => 'work-order-print-pdf',
                ),),
            array(
                'icon' => 'fa fa-print fa-lg',
                'label' => Yii::t('app', 'Print'),
                'visible' => true,
                'itemOptions' => array(
                    'class' => 'work-order-print-selected',
                ),),))));

这是呈现的代码片段:

<div class="btn-toolbar">
  <div class="operations btn-group-sm btn-group open">
    <button id="export-or-email-btn" class="navbar-btn btn-sm btn btn-primary dropdown-toggle" data-toggle="dropdown" name="yt7" type="button">
      <span class="hidden-xs hidden-sm">Export</span> 
      <span class="caret"></span>
    </button>
    <ul id="yw6" class="dropdown-menu">
      <li class="work-order-export-btn nav-header" data-ol-has-click-handler="">
        <a href="#"><i class="fa fa-file-excel-o"></i> Export</a>
      </li>
      <li id="WorkOrder" class="email-export-btn nav-header" data-grid-id="work-order-grid" data-ol-has-click-handler="">
        <a href="#"><i class="fa fa-envelope-o"></i> Email Export</a>
      </li>
      <li class="work-order-export-import-btn nav-header" data-ol-has-click-handler="">
        <a href="#"><i class="fa fa-file-excel-o fa-lg"></i> Export as Import Template</a>
      </li>
    </ul>
    <button id="work-order-actions-btn work-order-actions" class="navbar-btn btn-sm btn btn-primary dropdown-toggle" style="margin: 0 0 0 15px;" data-toggle="dropdown" name="yt8" type="button">
      <span class="hidden-xs hidden-sm">Actions</span> 
      <span class="caret"></span>
    </button>
    <ul id="yw7" class="dropdown-menu">
      <li class="work-order-print-pdf nav-header">
        <a href="#"><i class="fa fa-print fa-lg"></i> Print PDF</a>
      </li>
      <li class="work-order-print-selected nav-header">
        <a href="#"><i class="fa fa-print fa-lg"></i> Print Selected</a>
      </li>
    </ul>
  </div>
</div>

我认为你的问题是你在同一个 $this->menu 属性中合并了两个数组。

也许您应该像文档中那样使用 CMenu 作为小部件

$this->widget('zii.widgets.CMenu', array(
    'items'=>array(
        // Important: you need to specify url as 'controller/action',
        // not just as 'controller' even if default action is used.
        array('label'=>'Home', 'url'=>array('site/index')),
        // 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
        array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
            array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
            array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
        )),
        array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
    ),
));

有关更多信息和属性,请查看 official documentation here