如何从组合框中禁用optgroup

时间:2010-11-21 18:04:50

标签: cakephp

HI, 我想从我的cakephp组合框中删除这个optgroup。我怎么能这样做?

此致 卡恩

1 个答案:

答案 0 :(得分:2)

好吧,如果你不想要它,就不要添加它。基本上,选择框用这样的单个数组填充:

$options = array(1=>'Text 1', 2=>'Text 2', ...);

让optgroup需要二维数组,如:

$options = array(
   'Opt Group 1'=>array(
      1=>'Text1',
      2=>'Text2',
      ...
   ),
   'Opt group 2'=>array(
      1=>'Text1',
      2=>'Text2',
      ...
   )
);

最有可能在您的控制器中而不是:

$this->set('options', $this->YourModel->find('list'));

您正在使用

$this->set('options', $this->YourModel->find('all'));

注意find函数中的参数。看看that article for Options parameter