我使用单一表单来创建和更新表单.我需要在下面的表单中默认选中复选框
<div class="row" style='float:left;;margin-left:5px'>
<?php echo '<span for="label" style="margin-bottom:5px;font-size: 0.9em;font-weight: bold;">Label</span><br />'; ?>
<?php echo $form->checkBox($model,'label_name',array('value'=>1,'uncheckValue'=>0,'checked'=>'checked','style'=>'margin-top:7px;')); ?>
<?php echo $form->error($model,'label_name'); ?>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用上面的代码来实现相同的目的我没有得到预期的结果.在更新表单时,即使未经检查,它也会显示已检查
我得到了解决方案我使用代码本身请看看
<div class="row" style='float:left;;margin-left:5px'>
<?php echo '<span for="label" style="margin-bottom:5px;font-size: 0.9em;font-weight: bold;">Label</span><br />'; ?>
<?php echo $form->checkBox($model,'label_name',array('value'=>1,'uncheckValue'=>0,'checked'=>($model->id=="")?true:$model->label_name),'style'=>'margin-top:7px;')); ?>
<?php echo $form->error($model,'label_name'); ?>
</div
Run Code Online (Sandbox Code Playgroud)