Check Box List Will Not Updated But List Box Will

hi i have three tables

deal, category, deal_category

colmuns in deal_category are deal_id and category_id, deal and category have many-many relation

i added category_deal with specifc deal_id and category_id and in the form of add deal use these codes for add category

<?php echo $form->listBox($model, 'categories', DealCategory::model()->categories, array('multiple'=>'true')); ?>

<?php echo $form->listBox($model,'categories', DealCategory::model()->categories) ?>


<?php echo $form->checkBoxList($model,'categories',DealCategory::model()->categories); ?>

as u can see i use three diffrent way but only first way work on update page and its because of html options array(‘multiple’=>‘true’), my problem is i want to use checkboxlist but on update page checkboxlist only select one category so its not right!

in the photo im added u can see what i mean



Hello, I think this post and this post here have similiar problem with yours

They suggest the same solution, it is to set the model’s attribute with array containing the key => values

i solve the problem ;D

because $select parameter in checkBoxList did not convert object to array we should pass attributes an array of selected categories so i do this

in model:

    public $preCategories=array();

    public function afterFind()


        foreach($this->categories as $category){

            $this->preCategories[] = $category->id;




in view form :

<?php echo $form->checkBoxList($model, 'preCategories', DealCategory::model()->categories); ?>