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(); ?>