在yii2中将函数传递给kartik文件上传器

时间:2015-11-21 12:08:03

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

我有一个表单,其中包含输入字段和使用ajax的kartik文件上传程序。我试图传递一个函数来获取表单字段的id并将其传递给上传者,但我总是收到错误

CODE:

视图

<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script src="controllers.js"></script>
<meta charset="UTF-8">
<title>Currency Service</title>
</head>
<body>
<div ng-app="financeApp" ng-controller="invoiceController as invoice">
<div>
    <select ng-model="invoice.inCurr">
        <option ng-repeat="c in invoice.currencies">{{c}}</option>
    </select>
</div>
<ul>
    <li ng-repeat="c in invoice.currencies">{{c + ' ' + getRate(c) + 'rate'}}</li>
</ul>
<ul>
    <li ng-repeat="r in invoice.usdToForeignRates">{{r}}</li>
</ul>
<button ng-click="invoice.add()">Add</button>
<div ng-model="invoice.counter">{{invoice.counter}}</div>
</div>
</body>
</html>

在控制器动作上传中,我测试是否传递了id(case_description)的值,但是我总是在上传器中包含uploadextra数据的行中得到null而出现意外[]错误

控制器代码

<?= $form->field($model, 'case_description',['id'=>'case_description'])->textArea();?>
<?php   echo $form->field($evidence, 'path')->widget(FileInput::classname(), [
                    'options' => ['accept' => '*','multiple' => true,'name'=>'images'],
                    'pluginOptions' => [
                 'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
                    'showPreview' => true,
                    'showCaption' => true,
                    'showRemove' => true,
                    'showUpload' => true,

                    'browseLabel' =>  'Insert Evidence',
                   'uploadUrl' => Url::to(['cases/upload']),
                   'maxFileCount' => 10,
                 'uploadExtraData' => function() {  // callback example
     return   $('#case_description').val() ;
 }],    

]
);?>

0 个答案:

没有答案