How to make all the checkboxes to be checked by using activeCheckBoxList()

Hi Qiang, good job of Yii… I am a PHP team leader of a domain name registration company. We found Yii on Google and decided to use it for our company's new project.

This moment I try to learn this framework while doing some code at same time. I solved lots of problem myself and also through the forum. But this one is really confusing me.

When I am using activeCheckBoxList(), I want to set the all checboxes to be checked by default. I used the following code:


It just doesn't work. Seems Yii filters text – 'checked' attribute out for $htmlOptions.

Then when I use array('Checked'='checked') – Capital C instead of c – It works fine. But I think this is not the proper way and there must be some standard way of doing it.

So could you tell me how to set all checkboxes to be checked for activeCheckBoxList()?

activeCheckBoxList requires the first parameter to be a model object, and the second parameter an attribute of the model. The attribute value is used to set the selections of the checkbox list. You don't need the last array (checked).

Yes, I know that… but can you give me an example of using it.


In above code, 'tld' is the attribute value I set – tld is the name of the checkboxes. so in the html code it shows <input type="checkbox" name="DomainCheckForm[tld][]" …/>

So what exactally should be for that attribute value… an example will be enough for me…

Many thanks

I got it finally!


above code set .net and .org as checked for checkboxlist – tld in domainCheck model

Yes, that's it, but you write it more elegantly as: