如何在kartik fileinput小部件中动态显示所有图像?

时间:2016-02-03 09:37:16

标签: file-io yii2

如何在initialPreview内动态显示所有图片?

<?php
$allimage = '';                         
foreach ($product_image as $index => $eachimage) {

    $baseurl = \Yii::$app->request->BaseUrl;
    $image_url = $baseurl.Yii::$app->params['show_product_big_path'].$eachimage['image_url'];                                   
    $allimage .= Html::img("$image_url",  ['class'=>'file-preview-image']);             
} 
    $allimage = trim($allimage, ',');

    echo FileInput::widget([
        'name' => 'productimage[]',
        'options'=>[
        'multiple'=>true,
        'id'=>'input-702',
    ],
      'pluginOptions' => [
        'initialPreview'=>[ 
            $allimage                                                                           
         ],
      'overwriteInitial'=>false
    ]
]);

?>
<?php } ?>

但是,它只显示initialPreview内的最后一张图片。 怎么可能?

1 个答案:

答案 0 :(得分:1)

将其放入数组(please refer doc)(点击Ctrl + F,然后输入initialPreview

<?php
$allimage = array();
foreach ($product_image as $index => $eachimage) {
    $baseurl = \Yii::$app->request->BaseUrl;
    $image_url = $baseurl.Yii::$app->params['show_product_big_path'].$eachimage['image_url'];
    $allimage[] = Html::img("$image_url",  ['class'=>'file-preview-image']);
}



echo FileInput::widget([
    'name' => 'productimage[]',
    'options'=>[
        'multiple'=>true,
        'id'=>'input-702',
    ],
    'pluginOptions' => [
        'initialPreview'=>$allimage,
        'overwriteInitial'=>false
    ]
]);

?>