yii checkBoxList调用数据库数据


yii中checkBoxList的用法是
<?php echo $form->checkBoxList($model,'fid',array(
'1'=>'中国',
'2'=>'日本',
'3'=>'美国',
'4'=>'德国',
),array('separator'=>'<br />','template'=>'{input} {label}')); ?>
 
我们把数据库中的

Controller中的actionCreate()方法中写入

$model->fid = array(1,2);//默认选中1和2选线

$this->render('opfunction',array(
'model'=>$model,
'B'=>$showB,
));

 

array('separator'=>'&nbsp;','labelOptions'=>array('class'=>'labelForRadio'))是要改变checkbox的显示格式,如果不改变,是竖着显示的,改变后是横排显示。如要更改的话还需要要CSS文件中的form中加入 

<style type="text/css">
label .labelForRadio{display:inline-block;width:auto;float:none;}
.checkbox{display:inline-block;width:auto;float:none; width:100px;}
</style>

checkBoxList是表单里面的,使用$form->checkBoxList(的时候须在前面加上下面的widgets.TbActiveForm

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'plat-form-user-form',
'type'=>'horizontal',
'enableAjaxValidation'=>false,
)); ?>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM