2

我想禁用选择输入中的选项,所以我尝试了:

echo $this->Form->select("status", 
    [
    'options' => $status, 
    'value' => $order->status, 
    'label' => false, 
    'disabled' => [1, 2]
    ]);

但它不会disabled在 html 代码中生成任何语句。

我的错误是什么?

4

2 回答 2

2

将属性设置为选择选项的正确方法是传递这样的数组

$options = [
    [ 'text' => 'option 1', 'value' => 'value 1', 'disabled' => true],
    [ 'text' => 'option 2', 'value' => 'value 2', 'disabled' => true],
    [ 'text' => 'option 3', 'value' => 'value 3'],
    [ 'text' => 'option 4', 'value' => 'value 4']
];

echo $this->Form->select(
    'status', 
    $options, 
    ['value' => $order->status, 'label' => false]
);
于 2016-01-04T12:50:58.773 回答
2

您应该使用 FormHelper 的输入功能并设置 type = "select"
.My sample(只能选择三个)

$status = [1 => 'One', 2 => 'Two', 3 => 'Three'];
echo $this->Form->input("status", 
    [
    'type' => 'select',
    'options' => $status, 
    'label' => false, 
    'disabled' => [1, 2]
    ]
);
于 2016-03-17T03:06:27.373 回答