dastanaron/yii2-dropzone-widget
Composer 安装命令:
composer require 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
README 文档
README
На русском ТУТ
Widget for convenient downloading of files, using the well-known library DropZone.js.
This widget differs from many in that:
- Everything works, including converting the php array to a JS object.
- 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.
Either run
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.
First add the module to main.php:
<?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)
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)
Example of a data acceptance controller, details here:
<?php use Yii; use yii\web\Controller; use backend\models\UploadImage; use yii\web\UploadedFile; class DynamikjsController extends Controller { public function actionImageUpload() { $model = new UploadImage(); if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstanceByName('file'); if ($model->upload()) { return 'ok'; } } Yii::$app->response->setStatusCode(400); return 'error'; } }
统计信息
- 总下载量: 1.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-15