0

So I'm trying to create a dynamic Checkbox List in Yii2. I'm trying to adept the work done here but without success. As described there i should use the ArrayHelper.

So first I am fetching the data (works)

$listData=ArrayHelper::map(EinsatzorteModel::find()->asArray()->all(),'id','location'); 

Output(shortend):

array(9) { 
   [1]=> string(18) "Region: Y" 
   [2]=> string(17) "Region: X"
}

Now I'm trying to add it to a checkbox list:

<?= $form   ->field($model, 'locations[]')
           ->checkboxList(
            [$listData]
           )->label('Regionen');
?>

Which errors to:

htmlspecialchars() expects parameter 1 to be string, array given

Obviously its an Array, but shouldn't it fit anyway? The checkbosList expects parameters to be given as

'A' => 'Item A'

which actually should fit the format from the ArrayHelper.

So where do I get it wrong?

1 Answer 1

1

You should simply try $listData instead of [$listData].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.