Dear oflodor
I hope the following would serve the purpose in your case.
Let us assume that we have table item: columns id, name,brand..
Items are catagorized internally by different brands.
Now if we want to create a checkBoxList on some other model.
We can do the following.
$data=CHtml::listData(Item::model()->findAll(),'id','name','brand');
foreach($data as $brand=>$itemList)
{ echo $brand;
echo CHtml::activeCheckBoxList($model,'someAttribute',$itemList,array('container'=>'div','style'=>'margin-left:10px;'));
}
Let us consider a relation.
Table item Model Item: columns id,name ,b_id
Table brand Model Brand :columns id,name.
Relation between Item and Brand.
Item.php
public function relations()
{
return array(
'brand' => array(self::BELONGS_TO, 'Brand', 'b_id'),
);
}
We can do the following to create a checkBoxList.
$data=CHtml::listData(Item::model()->with('brand')->findAll(),'id','name','brand.name');
foreach($data as $brand=>$itemList)
{ echo $brand;
echo CHtml::activeCheckBoxList($model,'someAttribute',$itemList,array('container'=>'div','style'=>'margin-left:10px;'));
}
Regards.