如何在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
内的最后一张图片。
怎么可能?
答案 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
]
]);
?>