CakePHP 自定义下拉菜单

CakePHP Custom Dropdown Menu

我有一个下拉列表,项目很多(超过 20 项)。

我正在使用 CakePHP,这就是我编写下拉列表的方式:

<?php
     echo '<div class="form-group">';
     echo $this->Form->input('type', array(
         'class' => 'form-control',
         'id' => 'listType',
         'options' => array(
                'Item 1' => 'Item 1',
                'Item 2' => 'Item 2',
                'Item 3' => 'Item 3'),
         'empty' => '--Choose Item Type--',
         'label' => false
     ));
     echo '</div>';
?>

现在,我的下拉列表中有一些项目有子项目。有什么办法吗?

比如像这样的下拉:

Fruits
   Apple
   Banana
   Orange
   Grape
Vegetables
   Carrot
   Potato
Chips
Sausage

我希望除了子项目之外的所有项目都可以点击。我还希望所有子项目都可以点击。

所以简而言之,项目'Fruits'和'Vegetables'不能点击,而其余的可以点击。有什么方法可以放置分隔线吗?

谢谢!如果有人能提供一个使用 CakePHP 格式的例子就更好了。

好的,经过几次实验,我终于想出了怎么做。

<?php
     echo '<div class="form-group">';
     echo $this->Form->input('type', array(
         'class' => 'form-control',
         'id' => 'listType',
         'options' => array(
                'Item 1' => 'Item 1',
                'Item 2' => array(
                     'Subitem 1' => 'Subitem 2',
                     'Subitem 2' => 'Subitem 2'
                ),
                'Item 3' => 'Item 3'),
         'empty' => '--Choose Item Type--',
         'label' => false
     ));
     echo '</div>';
?>
you should try this.
<?php
$data=array(
    'Fruits'=>array(
    'Apple',
    'Banana','Orange','Grape'),
    'Vegetables'=>array('Carrot','Potato'),
    'Chips',
    'Sausage'
);
         echo '<div class="form-group">';
         echo $this->Form->input('type', array(
             'class' => 'form-control',
             'id' => 'listType',
             'options' =>$data,
             'empty' => '--Choose Item Type--',
             'label' => false
         ));