如何在yii2

时间:2015-11-18 03:41:47

标签: php yii2 yii-extensions yii2-advanced-app

我使用的是dropzone文件上传器,但它没有采用活动形式的模型属性

dropzone小部件是:

echo \kato\DropZone::widget([
                       'options' => [
                          'url'=>'upload',
                           'maxFilesize' => '200',
                           'addRemoveLinks'=>true,

                       ],
                       'clientEvents' => [
                           'complete' => "function(file){console.log(file)}",
             'removedfile' => "function(file){alert(file.name + ' is removed')}"
                       ],
                   ]);

我试过了

echo $form->field($model, 'picture')->widget(\kato\DropZone::widget([
                       'options' => [
                           'url'=>'upload',
                           'maxFilesize' => '200',
                           'addRemoveLinks'=>true,

                       ],
                       'clientEvents' => [
                           'complete' => "function(file){console.log(file)}",
             'removedfile' => "function(file){alert(file.name + ' is removed')}"
                       ],
                   ])); 

但它会返回一个像这样的错误

Class '<div id="myDropzone" class="dropzone"><div id="previews" 
class="dropzone-previews"></div></div>' not found

1 个答案:

答案 0 :(得分:1)

通常应该是:

use kato\DropZone;

...

echo $form->field($model, 'picture')->widget(DropZone::className, [
    'options' => [
        'url'=>'upload',
        'maxFilesize' => '200',
        'addRemoveLinks'=>true,
    ],
    'clientEvents' => [
        'complete' => "function(file) { console.log(file) }",
        'removedfile' => "function(file) {alert(file.name + ' is removed') }",
    ],
]);

所以在第一个参数中传递一个类名,在第二个 - 带有选项的配置数组中。

但我看了一个小部件的sources,没有支持。在没有ActiveField的情况下使用它,或者在GitHub上为此扩展创建问题/发送拉取请求。

官方文档:

yii\widgets\ActiveField widget()