mercredi 5 avril 2017

Getting an array of checkbox values in the controller

In the form there is such group of checkboxes

$form->field($model, 'ingredients')->checkboxList(
        ArrayHelper::map($ingredients, 'id', 'name')
    )

In html it looks like

<input name="Dish[ingredients][]" value="1" type="checkbox">
<input name="Dish[ingredients][]" value="2" type="checkbox">

How I can get an array of checkboxes values in the actionCreate method of controller?

I trying do it like this

Yii::$app->request->post('Dish[ingredients]', [])

but I get an empty array.




Aucun commentaire:

Enregistrer un commentaire