2017 © Pedro Peláez
 

yii2-extension yii2-dropzone-widget

A widget that uses the well known dropzone library for convenient file uploads. Does not throw scripts into the body of html, connects from its controller

image

dastanaron/yii2-dropzone-widget

A widget that uses the well known dropzone library for convenient file uploads. Does not throw scripts into the body of html, connects from its controller

  • Wednesday, January 17, 2018
  • by dastanaron
  • Repository
  • 0 Watchers
  • 1 Stars
  • 28 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 33 % Grown

The README.md

dropzone-widget

На русском ТУТ, (*1)

Widget for convenient downloading of files, using the well-known library DropZone.js., (*2)

This widget differs from many in that:, (*3)

  1. Everything works, including converting the php array to a JS object.
  2. Does not throw scripts into the body of an html document, than most widgets on yii2

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

composer require dastanaron/yii2-dropzone-widget "@dev" --prefer-dist 

After that, you need to configure the config. But this is only in case, if you use a widget with the generation of a JS file, and not with the publication of it in the body of html., (*6)

First add the module to main.php:, (*7)

<?php
    'modules' => [       
        //other modules //--//--//--//
        'dynamikjs' => [
            'class' => 'dastanaron\dropzone\DynamicJSModule'
        ],
    ]

Usage

<?=dastanaron\dropzone\DropZoneWidget::widget([
        'id' => 'myDropZone', // ID on the div element
        'site_url' => 'http://site.com/', //If you are using JS file generation, you must specify
        'generateJSFile' => true, //Generate js file (the default is on)
        'options'=> [
            'url' => '/file-upload/image-upload', //Where to send a request to save the file
            'maxFiles' => 1, //The maximum number of files
            'acceptedFiles' => 'image/*', // MIME - file types
        ],
        'events' => [
            'success' => 'function(event, response) {
                console.log("success")
                $("input#inputid").val(response.id);
            }',
        ],
]);?>

In the array of options, you can specify all the options available in dropZoneLib, [list of options] (http://www.dropzonejs.com/#configuration-options), (*8)

In the events array, you can pass functions to handledropZone.on ("event", function () {})the key will be your event, and the function is the function passed to handle the specified event. The dropZone events are indicated [here] (http://www.dropzonejs.com/#event-list), (*9)

Example of a data acceptance controller, details here:, (*10)

```php <?php, (*11)

use Yii; use yii\web\Controller; use backend\models\UploadImage; use yii\web\UploadedFile;, (*12)

class DynamikjsController extends Controller { public function actionImageUpload() { $model = new UploadImage();, (*13)

    if (Yii::$app->request->isPost) {
        $model->file = UploadedFile::getInstanceByName('file');
        if ($model->upload()) {
            return 'ok';
        }
    }

    Yii::$app->response->setStatusCode(400);
    return 'error';
}

}, (*14)

The Versions

17/01 2018

dev-master

9999999-dev

A widget that uses the well known dropzone library for convenient file uploads. Does not throw scripts into the body of html, connects from its controller

  Sources   Download

MIT

The Requires

 

by Avatar dastanaron

extension yii2 widget dropzone