0

我想要 yii2-fileinput-widget 中的更多按钮。

我当前的代码是这样的:

$allPics = \common\models\Picture::getPictures($album->id);
$images = [];
$imagesOptions = [];
if($allPics){
    foreach ($allPics as $pic){
         $key = $pic->id;
         $url = Url::to(['set-pic-status', 'id'=>$key, 'pid'=>$model->id, 'do'=>'remove']);
         $images[] = Yii::$app->urlManagerFront->createAbsoluteUrl(['image/index', 'id'=>$pic->id, 'width'=>300, 'height'=>300]);
         $imagesOptions[] = ['caption' => $pic->name, 'size' => $pic->size , 'url'=>$url, 'key'=>$key];
    }
} 
echo FileInput::widget([
     'name' => 'pic',
     'language'=>'fa',
     'options'=>[
         'multiple'=>true
     ],
     'pluginOptions' => [
         'uploadUrl' => Url::to(['pic-upload', 'id'=>$model->id]),
         'initialPreview'=>$images,
         'initialPreviewAsData'=>true,
         'initialCaption'=>"تصاویر محصول",
         'initialPreviewConfig' => $imagesOptions,
         'overwriteInitial'=>false,
         'maxFileSize'=>2800,
     ]
]);

顶级代码的结果是: 在此处输入图像描述

现在我需要在删除按钮附近再添加一个按钮来向服务器发送一些数据并将所选图片设置为封面或更改数据库中图片的状态。

我怎样才能做到这一点?

4

1 回答 1

1

试试这个:

$initialPreview = [];
$initialPreviewConfig = [];
foreach($model->images as  $image){
$initialPreview[] = Html::img($image->imagePath,['width' =>200]);
$initialPreviewConfig[] = [
    'url' => \yii\helpers\Url::to(['/admin/portfolio/portfolio/image-delete']),
    'key' => $image->ID,

];
}

?>
<br>
<div class="row">
    <div class="col-md-12">
        <?php
        echo FileInput::widget([
            'name' => 'ProductImages[]',
            'options'=>['accept'=>'image/*','multiple' => true],
            'pluginOptions' => [
                'otherActionButtons' => '<button class="set-main" type="button" {dataKey} ><i class="glyphicon glyphicon-star"></i></button>',
                'overwriteInitial'=>false,
                'maxFileSize'=>2800,
                'fileActionSettings' => [
                    'fileActionSettings' => [
                        'showZoom' => false,
                        'showDelete' => true,
                    ],
                ],
                'browseClass' => 'btn btn-success',
                'uploadClass' => 'btn btn-info',
                'removeClass' => 'btn btn-danger',
                'showRemove' => false,
                'showUpload' => false,
                'initialPreview' => $initialPreview,
                'initialPreviewConfig' => $initialPreviewConfig,

            ],

        ]);
        $this->registerJs("
    
            $('.set-main').on('click',function(){
                $.get('" . \yii\helpers\Url::to(['/admin/portfolio/portfolio/set-main-image/']) . "', {id:$(this).attr('data-key')});
                
                });
    ");
        ?>

    </div></div>
<div>

'其他动作按钮' => '...';

于 2018-02-06T13:48:14.920 回答