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,
)); ?>

posted on 2013-03-26 14:18  划风  阅读(4253)  评论(0)    收藏  举报

导航