0

我有我的动态表单,其中使用 wbraganca 小部件和 kartik 文件上传。当我打开页面时,该字段只显示微调器图像而不是文本字段,并且控制台显示“无法识别的表达式:#tcandidateexp-{$i}-prod_per_year_file ”。我想用作文件上传的字段是“prod_per_year_file”。任何帮助将不胜感激。谢谢。

<?php $form = ActiveForm::begin(['id' => 'dynamic-form', 'options'=>['enctype'=>'multipart/form-data']]); ?>
<div class='row'>    
    <?php DynamicFormWidget::begin([
        'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
        'widgetBody' => '.container-items', // required: css class selector
        'widgetItem' => '.item', // required: css class
        'limit' => 5, // the maximum times, an element can be added (default 999)
        'min' => 1, // 0 or 1 (default 1)
        'insertButton' => '.add-item', // css class
        'deleteButton' => '.remove-item', // css class
        'model' => $models_exp[0],
        'formId' => 'dynamic-form',
        'formFields' => [
            'start_year',
            'end_year',
            'company',
            'prod_per_year',
            'prod_per_year_file',
            'inc_per_year',
            'inc_per_year_file'
        ],
    ]); ?>

    <div class="panel panel-default" style="width:85%">
        <div class="panel-heading">
            <h4>
                <i class="glyphicon glyphicon-envelope"></i> Experiences
                <button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
            </h4>
        </div>
        <div class="panel-body">
            <div class="container-items"><!-- widgetBody -->
            <?php foreach ($models_exp as $i => $model_exp): ?>
                <div class="item panel panel-default"><!-- widgetItem -->
                    <div class="panel-heading">
                        <h3 class="panel-title pull-left">Detail</h3>
                        <div class="pull-right">
                            <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="panel-body">
                        <?php
                            // necessary for update action.
                            if (! $model_exp->isNewRecord) {
                                echo Html::activeHiddenInput($model_exp, "[{$i}]id");
                            }
                        ?>

                        <div class="row">
                            <div class="col-sm-6" >
                                <?=                                         
                                    $form->field($model_exp, "[{$i}]start_year")->textInput();
                                ?>
                            </div>

                            <div class="col-sm-2">
                                <?= 
                                    $form->field($model_exp, "[{$i}]end_year")->textInput();
                                ?>
                            </div>
                            <div class="col-sm-2">
                                <?= 
                                    $form->field($model_exp, "[{$i}]company")->textInput();
                                ?>
                            </div>

                            <div class="col-sm-10">
                                <?= $form->field($model_exp, "[{$i}]prod_per_year")->textInput() ?>
                            </div>

                            <div class="col-sm-10">
                                <?php 
                                    //$form->field($model_exp, "[{$i}]prod_per_year_file")->textInput()
                 echo $form->field($model_exp, '[{$i}]prod_per_year_file')->widget(FileInput::classname(), [
                                        'pluginOptions' => [
                                            'showPreview' => false,
                                            'showCaption' => true,
                                            'showRemove' => true,
                                            'showUpload' => false
                                        ]
                                    ]);  
                                ?>
                            </div>

                            <div class="col-sm-10">
                                <?= $form->field($model_exp, "[{$i}]inc_per_year")->textInput() ?>
                            </div>

                            <div class="col-sm-10">
                                <?= $form->field($model_exp, "[{$i}]inc_per_year_file")->textInput() ?>
                            </div>
                        </div><!-- .row -->
                    </div>
                </div>
            <?php endforeach; ?>
            </div>
        </div>
    </div><!-- .panel -->
    <?php DynamicFormWidget::end(); ?>
</div>
4

1 回答 1

0

尝试用双引号替换单引号

echo $form->field($model_exp, "[{$i}]prod_per_year_file")->widget(FileInput::classname(), [
                                        'pluginOptions' => [
                                            'showPreview' => false,
                                            'showCaption' => true,
                                            'showRemove' => true,
                                            'showUpload' => false
                                        ]
                                    ]); 
于 2017-07-26T03:07:25.727 回答