Yii:如何从数组

时间:2016-03-16 08:16:53

标签: php arrays yii

我正在使用Yii 1.1.17。我想知道如何将禁用选项添加到数组的下拉列表中。我知道如何逐个添加选项

echo CHtml::tag('td', array('class' => 'row'),
    CHtml::dropDownList(
        'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
        $attr->C_FTYPE,
        TicketTypeAttribute::itemAlias('C_FTYPE'),
        [
            'options' => [
                'INT' => ['disabled' => 'disabled']
            ],
            'style' => 'width: 97%;',
            'class' => 'ftype'
        ]
    )
);

但有没有办法从数组添加它?

if($attr->C_FTYPE == 'DATETIME') {
    $disallow = ['DECIMAL', 'INT', 'BOOLEAN', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
} else {
    $disallow = ['INT', 'BOOLEAN', 'DECIMAL', 'DATETIME', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
}

这样的东西
echo CHtml::tag('td', array('class' => 'row'),
    CHtml::dropDownList(
        'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
        $attr->C_FTYPE,
        TicketTypeAttribute::itemAlias('C_FTYPE'),
        [
            'options' => [
                $disallow => ['disabled' => 'disabled']
            ],
            'style' => 'width: 97%;',
            'class' => 'ftype'
        ]
    )
);

1 个答案:

答案 0 :(得分:1)

很容易自己构建阵列

$disallowed_options = [];

foreach($disallow as $option_key){
  $disallowed_options[$option_key] = ['disabled'=>'disabled'];
}

然后在你的配置

'options'=> $disallowed_options,