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

70gysomp  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(113)

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

我正在尝试创建一个按钮菜单,其中包含两个下拉菜单按钮,每个按钮都包含子菜单项,如下所示:Drop Down Button Group
但是Yii CMenu引擎呈现的是两个重叠的下拉菜单,并且都是由相同的按钮触发的。比如:enter image description here
查看呈现的代码,看起来像是CMenu(或任何支持引导程序的库)为两个下拉菜单分配了“dropdown-menu”类,并且由于它们位于同一个按钮组中,因此当分配“open”类时,它会同时打开两个下拉菜单。
所以我的问题很简单,甚至可以使用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>
brccelvz

brccelvz1#

我认为你的问题是你在同一个$this-〉菜单属性中合并了两个数组。
也许您应该像文档中那样使用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

相关问题