0

what parameters to add in my code?

$form->checkBox($model,'ATTRIBNAME',array("id"=>"mybox"));?> 

i wanna display the checkbox as checked if the value from the db is 1 and unchecked if the value it got from the db is 0 ?

4

3 に答える 3

2

If the value of $model->ATTRIBNAME=1 then $form->checkBox(...) method automatically check the checkbox, 0 for uncheck

$model->ATTRIBNAME = 1;  // 0 for uncheck

//Now it displays checked box
$form->checkBox($model,'ATTRIBNAME',array("id"=>"mybox"));
于 2012-10-22T07:14:47.483 に答える
0

チェックされた属性を追加する

if ($value==1) {$attrs=array("id"=>"mybox","checked"=>"checked");}
if ($value==0) {$attrs=array("id"=>"mybox");}
$form->checkBox($model,'ATTRIBNAME',$attrs);
于 2012-10-22T02:53:05.433 に答える
0

Small code

$form->checkBox($model,'ATTRIBNAME',array("id"=>"mybox","checked"=>($value==1)?"checked":""));
于 2012-10-22T08:51:23.257 に答える