acriveCheckBoxList with checked attribute. how to?

How can I define that a checkbox of the activeCheckBoxList is checked?

$model->$attribute should contain the value that choose which checkboxes to be checked.

Hi, I am new to Yii and having the similar problem with checboxlist.

In my "AddAdminForm" model:





    public $select_function1 = array();


    public function  __construct()

    {

        $this->function_level1 = dbAdmin::selectAdminCode(1);

    }



here i am using DAO rather activerecord because i only have synonyms permission for the tables.

in view:




       <?php echo CHtml::activeCheckBoxList($model, 'select_function1', $model->function_level1, array("checkAll"=>"Select All")); ?>



in my controller:




            $model->attributes=$_POST['AddAdminForm'];


            echo '<br>==============<br>';

                var_dump($model->select_function1);

            echo '<br>==============<br>';




but the result is empty:





==============

array(0) { } 

==============




on the other hand, i did see the checkboxlist is populated correctly with the value retrieved from db:




    'function_level1' => array

    (

        '01' => 'Create Event'

        '02' => 'Config Package - retrieve'

        '03' => 'Config Package - commit'

        '04' => 'Event List - retrieve'

        '05' => 'Event List - commit'

        '06' => 'Edit Event - retrieve'

        '07' => 'Edit Event - commit'

        '08' => 'Download Report'

        '09' => 'Search Registration'

    )



Sorry, I found out that the problem is with my $select_function1 declaration. It should be :




public $select_function1;



Now the checkbox values are passed to controller after form submit. However the checkboxlist does not retain the status after submit, meaning all checkbox will remain unchecked. Is there something wrong again?

Ops…it is working now!

I finally found out I must mark the checkbox to be required or safe in order for its status maintained before/after the form submition.