Checkbox in view.php and _view.php

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">

&lt;b&gt;&lt;?php echo CHtml::encode(&#036;data-&gt;getAttributeLabel('iGrupoID')); ?&gt;:&lt;/b&gt;


&lt;?php echo CHtml::link(CHtml::encode(&#036;data-&gt;iGrupoID), array('view', 'id'=&gt;&#036;data-&gt;iGrupoID)); ?&gt;


&lt;br /&gt;





&lt;b&gt;&lt;?php echo CHtml::encode(&#036;data-&gt;getAttributeLabel('vchNome')); ?&gt;:&lt;/b&gt;


&lt;?php echo CHtml::encode(&#036;data-&gt;vchNome); ?&gt;


&lt;br /&gt;





&lt;b&gt;&lt;?php echo CHtml::encode(&#036;data-&gt;getAttributeLabel('bPedidoExcepcao')); ?&gt;:&lt;/b&gt;


[b]&lt;?php echo CHtml::checkBox(&#036;data-&gt;bPedidoExcepcao); ?&gt;[/b]


&lt;br /&gt;

</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.

http://www.yiiframework.com/forum/index.php/topic/20868-mysql-tinyint1-as-php-boolean/page__view__findpost__p__102222