douchixu3686 2016-01-19 23:06
浏览 49

在yii2中使用select2时,为foreach()错误提供的参数无效

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条回答 默认 最新

  • duanqilupinf67040 2016-01-20 13:46
    关注

    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

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部