Hi
How can I use a checkbox in update Yii forms (view.php) to reflect a boolean value from a database?
Tks
BSC
Hi
How can I use a checkbox in update Yii forms (view.php) to reflect a boolean value from a database?
Tks
BSC
Have you tried to do it?
Can you post your code?
Yes, I can use the checkbox, but for the update and list pages I cannot make it checked if the value from the boolean field in the database is 1/true.
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('iGrupoID')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->iGrupoID), array('view', 'id'=>$data->iGrupoID)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('vchNome')); ?>:</b>
<?php echo CHtml::encode($data->vchNome); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('bPedidoExcepcao')); ?>:</b>
[b]<?php echo CHtml::checkBox($data->bPedidoExcepcao); ?>[/b]
<br />
</div>
tks/BSC
Check the documentation - http://www.yiiframew…checkBox-detail
You need a second parameter to set the status of the checkbox…
Try with
<?php echo CHtml::checkBox('name',$data->bPedidoExcepcao); ?>
I tried that. I have four records in the database, 2 true and 2 false. With your suggestion I get all the checkboxes checked.
Can I do something like:
<?php echo CHtml::checkBox(‘name’,assertEquals($data->bPedidoExcepcao,1)); ?>
or
<?php echo CHtml::checkBox(‘name’,assertEquals($data->bPedidoExcepcao,true)); ?>
I think the problem might be with the boolean field type in the MySQL database.
Any thoughts or ideas?
Solution here: http://www.yiiframework.com/forum/index.php?/topic/8276-boolean-preview-solved/page__p__41528__hl__boolean#entry41528
As I suspected it is a MySQL issue.
For google-ing purposes I post this solution for boolean types with gii model generation.