Is it possible to customise the array index generated by checkboxList()? For example:
<?php
$interests = [
[
'id' => 1,
'title' => 'title1',
'value' => 'value1',
],
[
'id' => 2,
'title' => 'title2',
'value' => 'value2',
],
];
?>
<?php echo $form->field($model, 'interests')->checkboxList($interests, [
'item' => function($index, $label, $name, $checked, $value) {
$return = '<div class="option">';
$return .= Html::checkbox($name, $checked, ['value' => $label['value'], 'id' => 'option-' . $label['id']]);
$return .= Html::label($label['title'], 'option-' . $label['id']);
$return .= '</div>';
},
]); ?>
The checkbox is generated as follows:
<input type="checkbox" name="Form[interests][]" value="1">
I want the following:
<input type="checkbox" name="Form[interests][title1]" value="1">
In other words, I want the array index to contain a value, rather than a zero-based numerical index.