Exemplo n.º 1
0
 public function afterUpload($data)
 {
     ImageDropzone::saveThumbnail($this->uploadDir . '/', $data['filename'], $this->thumbnail_width, $this->thumbnail_height);
     $image = new ProductImage(['product_id' => $data['params']['productId'], 'filename' => $data['filename'], 'image' => $data['src'] . $data['filename'], 'thumb' => $data['src'] . 'small-' . $data['filename'], 'description' => '', 'sort_order' => 50]);
     if ($image->save()) {
         return $image->toArray();
     } else {
         return $image->getErrors();
     }
 }
Exemplo n.º 2
0
            $fileType = \yii\helpers\FileHelper::getMimeType($file);
            $data = base64_encode(file_get_contents($file));
            echo "<img src='data:" . $fileType . ";base64," . $data . "' width=100><br>";
        } else {
            echo "<img src='{$image->thumb}' width=100><br>";
        }
        echo Yii::t('app', 'Sort Order') . ' <input style="width:50px" name="imageSort[' . $image->id . ']" value="' . $image->sort_order . '">';
        echo '</div>';
    }
    ?>
            <div style="clear:both"></div>
        </div>

        <div class="form-group">
            <?php 
    echo \backend\widgets\image\ImageDropzone::widget(['name' => 'file', 'url' => ['upload'], 'sortable' => true, 'sortableOptions' => [], 'htmlOptions' => [], 'options' => ['params' => ['productId' => $model->id]]]);
    ?>
        </div>

    <?php 
}
?>

    <div class="form-group">
        <label class="col-lg-2 control-label" for="">&nbsp;</label>
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php