I need to assign machines to a machine group (m:n). The mount of machines makes it necesary to use a gridview with checkboxcolumn to assign machines to a group. I got it to work that the relations are getting saved but I didn't figured it out how to make allready assigned machines to be checked in the gridview when it gets loaded. The content of my gridview is a dataprovider based on a MySQL-View. With
'checkboxOptions' => function($model, $key, $index, $column) {
return ['checked' => true];
}
it's possible to check all the checkboxes. But when I'm trying to do this
'checkboxOptions' => function($model, $key, $index, $column) {
$bool = in_array($model->id_machine, common\models\MachineGroup::getAssignedMachines());
return ['checked' => $bool];
}
an error is thrown: "Cannot use object of type yii\web\View as array". Actually I don't understand what's the problem here but I couldn't find a way to pass the array of the allready selected machines to this funtion (and I tried a lot). When I define a dummy-array manually in the function everything works fine. Need some help here...thanks!
Aucun commentaire:
Enregistrer un commentaire