Using $Form->Checkboxlist()

Hi I am new to Yii, started working few days ago on this framework.

I have a form to create where I am using 3 tables ("model","services_requested_options","countries"), first model to capture valued from all the fields to the database. I have successfully implemented the form with text fields using $form->textField()and dropdown for countries with $form->dropDownList() and also for errors using $form->error(), attached with a model with rules and its all working fine. Now I have 1 thing left to implement that is the list of checkboxes. I have to set them like the code in php below.

 foreach($services_requested_options as $services){ ?>

            <span class="form-checkbox-item" style="clear:left;">

              <input type="checkbox" class="form-checkbox" name="document_prep_services[servicesRequested][]" value="<?php echo $services->id; ?>">

              <label><?php echo $services->text." - $". showIn_numberFormat($services->charges). " USD";  ?> </label></span>

            <span class="clearfix"></span>


I think i should be using $form->checkBoxList() for this. But i am unable to do so.

The whole form is working on $model while this checkboxes are being fetched from another table, the values of which are in array $services_requested_options.

Now I have to store its values in $model->attributes in another table while running above code in yii… I hope you are understanding my point. Also it should show an error if all the checkboxes are unchecked, atleast checkbox should be checked.

I couldn’t find any solution for this over internet. Can anyone help me?

To get a list of all services from the services table, try


   echo $form->CheckBoxList($model,'services',

                            CHtml::listData(Services::model()->findAll(), 'services_id', 'services_name'));