Hi, I have ModelA and ModelB with relation MANY_MANY.
I’m using form builder to create form for ModelA, and I need to view a list of checkboxes (checked and/or not checked) with id/values taken from ModelB.
I’ve enstablished relation using relations() function, but I still don’t understand how to view relational checkboxes.
I’ve tried with this function in ModelA:
public function getItems(){
$model = ModelB::model()->findAll();
foreach($model as $k=>$v):
$arr[$v->id] = $v->name;
endforeach;
return $arr;
}
It works in the sense that it displays all items from ModelB but -of course- it doesn’t work as I want because it doesn’t display checked boxes, and it doesn’t update table that joins ModelA with ModelB. Maybe I have to write code to do that? I mean to know if a check is checked in getItems function and an INSERT statement in a afterSave() function to update join table?
It display all 4 checkboxes but I’ve tried for a few hours to make checkboxes 1 & 3 checked and it seems not possible. I hope I’m doing something wrong because i cannot believe that checkboxlist doesn’t implement a way to render checkboxes checked/unchecked. Either with ‘attributes’ key (that is passed as htmlOptions) doesn’t work because it assigns key/value couple to all checkboxes… Just to be clear: