Checkboxlist

I have a email form that contains check boxes that uses checkBoxList to list the data model alphabetically…




$criteria = new CDbCriteria;

$criteria->order = 'name';


echo $form->checkBoxList($model, 'communities', CHtml::listData(Community::model()->findAll($criteria), 'name', 'name'));



A simplified version of the list would look like this…

A

B

C - 1 (The Cs are all separate records but have the same name except for after the dash)

C - 2

C - 3

D

I would like to move B to the bottom of the list and also combine all the Cs into one check box labeled as only C (without the ’ - #’). The list would look like this…

A

C

D

B

I can’t figure out how to do this with checkBoxList. Is there an easy way to do this that I am overlooking?

I hope I have explained this clearly enough.

Thanks in advance for your help!

Dear Friend

I hope the following will do the things.




$data=CHtml::listData(Community::model()->findAll($criteria), 'name', 'name');

foreach($data as $i=>$j)

{       


       if($j[0]=='C')

	{ 

           unset($data[$i]);

	   $data['C']="C";

	}

}


ksort($data);


foreach($data as $i=>$j)

{     

	if($j==="B")

	{  unset($data[$i]);

	   $data[$i]=$j;

        }       

}


print_r($data);



Thanks for your reply. After I posted my question I started working on it and came up with something very similar to your suggestion. Good to know I was on the right track!

Thanks again