为了向用户显示选项列表,我使用了以下代码:
public function getData($property)
{
$data=array(
'membership_fee' => array(
'Large Company & Organisation',
'Medium Company & Organisation',
'Small Company & Organisation ',
'Mini- Company & Organisation',
'Individual Membership ',
'Large Company & Organisation ',
'Medium Company & Organisation ',
'Small Company & Organisation',
'Mini- Company & Organisation ',
'Individual Membership ',
),
);
return $data[$property];
}
和
<div class="form-group">
<?= $form->labelEx($model, 'membership_fee', array('class' => 'col-xs-12 col-sm-4 control-label')) ?>
<div class="col-xs-12 col-sm-8">
<?= $form->radioButtonList($model, 'membership_fee', $model->getData('membership_fee'), array(
'template' => '<div class="radio col-xs-12 col-sm-6">{beginLabel}{input}{label}{endLabel}</div>',
'separator' => '',
)); ?>
<?= $form->error($model, 'membership_fee') ?>
</div>
</div>
但是,这些代码是以数字的形式保存数据(例如,如果用户选择 Large company and org,则将其保存到数据库中为 0,或者如果用户选择 miduim company and org,则将其保存到数据库中为 1)。我需要将数据作为选择的选项标题而不是数字保存到数据库中。我该怎么做?