我在listData中有一个数组,我想通过activeDropDownList获取值,而不是索引,这是我的代码:
$salaries=array('1000$', '2000$', '3000$', '4000$', '5000$');
echo CHtml::activeDropDownList($model,'salary', $salaries,
array('empty'=>'Select salary',
'style'=>'width:300px', 'class'=>'form-control'));
当数据发送到控制器的值为$ model-> salary = 1,如果用户选择2000 $,我希望该值为2000 $。
答案 0 :(得分:2)
试试这个array_combine
$salaries=array_combine($salaries,$salaries);
你得到数组array('1000$'=>'1000$','2000$'=> '2000$','3000$'=> '3000$', '4000$'=> '4000$', '5000$'=> '5000$')
这是你应该的,
$salaries=array('1000$', '2000$', '3000$', '4000$', '5000$');
$salaries=array_combine($salaries,$salaries);
echo CHtml::activeDropDownList($model,'salary', $salaries,
array('empty'=>'Select salary',
'style'=>'width:300px', 'class'=>'form-control'));