我已经使用此代码填充Checkbox ..但它不工作

时间:2013-12-07 05:40:56

标签: php yii

foreach($add_details_arr as $key=>$val1){

    if($val1 == '1'){
            $ck1=  "checked=>'checked'";
    }else{
            $ck1= '';
    } if($val1 == '2'){
            $ck2=  "checked=>'checked'";
    }else{
            $ck2= '';
    }
}

在我看来

<?php echo CHtml::activecheckBox($model,'setting[0]',array('value'=>'1','uncheckValue'=>null, 'class'=>'radio',checked=>$ck1)); ?>
<?php echo CHtml::activecheckBox($model,'setting[1]',array('value'=>'2','uncheckValue'=>null, 'class'=>'radio',checked=>$ck2)); ?>  

1 个答案:

答案 0 :(得分:0)

试试这个 -

    foreach($add_details_arr as $key=>$val1){

        if($val1 == '1'){
                $ck1 =  'checked';
        }else{
                $ck1= '';
        } if($val1 == '2'){
                $ck2=  'checked';
        }else{
                $ck2= '';
        }
       echo CHtml::activecheckBox($model,'setting[0]',array('value'=>'1','uncheckValue'=>null, 'class'=>'radio',checked=>$ck1));
       echo CHtml::activecheckBox($model,'setting[1]',array('value'=>'2','uncheckValue'=>null, 'class'=>'radio',checked=>$ck2));
    }