doukun1450 2016-09-26 06:36
浏览 98
已采纳

如何在yii 1中使用radioButton

In order to display the list of options to the users, I used following code:

  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];
    } 

and

<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>

But, these codes are saving data as the form of number (eg. if user chooses Large company and org it saves it to the database as 0, or if user chooses miduim company and org it saves it to the database as 1). I need to save data to the database as choosen option title not as number. How can i do it?

  • 写回答

1条回答 默认 最新

  • doushao6874 2016-09-26 06:44
    关注

    You need to convert $data like below:-

    $data=array(
        'membership_fee' => array(
        'Large Company & Organisation'=>'Large Company & Organisation',
        'Medium Company & Organisation'=>'Medium Company & Organisation',
        'Small Company & Organisation'=>'Small Company & Organisation',
        'Mini- Company & Organisation'=>'Mini- Company & Organisation',
        'Individual Membership'=>'Individual Membership',
        'Large Company & Organisation'=>'Large Company & Organisation',
        'Medium Company & Organisation'=>'Medium Company & Organisation',
        'Small Company & Organisation'=>'Small Company & Organisation',
        'Mini- Company & Organisation'=>'Mini- Company & Organisation',
        'Individual Membership'=>'Individual Membership',
    ),
    

    Note:- instead of data numbers will goes in your case because your array is look like :- Array(0=>'Large Company & Organisation',1=>'Medium Company & Organisation' ....... so on)

    Reference taken:- http://www.yiiframework.com/forum/index.php/topic/10621-radio-button/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计