1
votes

I am making a many to many relationship between my blog tables and tag tables , now i'm trying to get the post tags with kartik select2 , i've made an instance of my tag model to use it in select2 in active form but i get the Invalid argument supplied for foreach() error when I open the insert page . and here is my form which i've already passed the $model and $tagModel which are the instances of my activeRecord models with render from my controller . here is my form :

<?php

$form = ActiveForm::begin([
            'options' => ['enctype' => 'multipart/form-data'],
        ]);
?>

<?= $form->field($model, 'title')->textinput(); ?>
<?= $form->field($model, 'blog')->textarea(); ?>
<?= $form->field($model, 'imageFile')->fileinput(); ?>

<?=

$form->field($tagModel, 'tag')->widget(Select2::classname(), [
    'data' => 'data',
    'options' => ['placeholder' => '...تگ ها را انتخاب کنید'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);
?>

<?= Html::SubmitButton('ارسال', ['class' => 'btn btn-success green']); ?>

<?php ActiveForm::end(); ?>
1
I've installed and use(d) the widget name space completely and it works fine without model , but i'm trying to use my models here ... - TheDevWay
data must be an Array in Select2 widget see demos.krajee.com/widget-details/select2#settings - Double H
thank you , i got the problem <3 - TheDevWay

1 Answers

0
votes

i cant see the foreach in your code here but as we all know that foreach are used for arrays

i think data should be an array