Yii2 checkbox value is not posting to controller


I am using Yii2 checkbox for passing some id’s from a form to the controller when selected. Here is my code,

<?= Html::activeCheckbox($model, 'attribute['.$dynamic_index.']', ['value'=>$dynamic_value]); ?>

But while posting the form data to the controller I couldn’t get the values of the checked checkboxes.

It always giving me the 0 value from the hidden input field. Don’t know why ?

Any help will be appreciated.

I think you put the dynamic_index in a wrong place

try this

<?= Html::activeCheckbox($model, "[$dynamic_index]attribute", ['value'=>$dynamic_value]); ?>