yii checkBoxList调用数据库数据
yii中checkBoxList的用法是
<?php echo $form->checkBoxList($model,'fid',array(
'1'=>'中国',
'2'=>'日本',
'3'=>'美国',
'4'=>'德国',
'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'=>' ','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,
)); ?>
作者:划风
邮箱:emaisi@hotmail.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
浙公网安备 33010602011771号