1

我有这个 xupload 文件扩展名:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file1',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form1',
            'uploadView' => 'application.views.somemodel.upload1',
            'downloadView' => 'application.views.somemodel.download1',
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

我需要添加另一个上传文件字段,但是当我复制这样的代码时:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file2',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form2',
            'uploadView' => 'application.views.somemodel.upload2',
            'downloadView' => 'application.views.somemodel.download2',
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

问题是当我为两个上传文件上传图片时,它适用于相同的上传模板,我尝试添加 uploadTemplate、downloadTemplate 选项但它不起作用,请告诉我如何使用 uploadTemplate、downloadTemplate 以及如何渲染为 renderPartial 以及我在哪个文件中渲染它,我应该在这一行更改 id < script id="template-upload" type="text/x-tmpl"> 和 < script id="template-download" type="text/x-tmpl"> upload.php 和 download.php 模板文件,请告诉我该怎么做?

非常感谢

4

1 回答 1

2

我从来没有在同一页面中使用 XUpload 和超过 1 个小部件,但试试这个:

为您的每个表单模板 (application.views.somemodel.form1application.views.somemodel.form2) 添加一个类,即。'上传文件':

//application.views.somemodel.form1
<form class="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
    <!-- ... -->
</form>

//application.views.somemodel.form2
<form class="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
    <!-- ... -->
</form>

uploadView为每个和创建不同的 id ,downloadView即:

//application.views.somemodel.upload1
< script id="template-upload1" type="text/x-tmpl">
//application.views.somemodel.download1
< script id="template-download1" type="text/x-tmpl">

//application.views.somemodel.upload2
< script id="template-upload2" type="text/x-tmpl">
//application.views.somemodel.download2
< script id="template-download2" type="text/x-tmpl">

并按如下方式配置您的小部件:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file1',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form1',
            'uploadView' => 'application.views.somemodel.upload1',
            'downloadView' => 'application.views.somemodel.download1',
            'uploadTemplate' => '#template-upload1', // IMPORTANT!
            'downloadTemplate' => '#template-download1',// IMPORTANT!
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file2',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form2',
            'uploadView' => 'application.views.somemodel.upload2',
            'downloadView' => 'application.views.somemodel.download2',
            'uploadTemplate' => '#template-upload2', // IMPORTANT!
            'downloadTemplate' => '#template-download2',// IMPORTANT!
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>
于 2013-01-17T13:53:32.483 回答