yii2从一个表创建动态表单?

时间:2016-11-04 09:12:05

标签: yii2 yii2-basic-app

我有一个名为project的表,因为我想为两个用户和角色字段创建动态表单。这些字段是来自另一个表值的下拉列表。

<?php $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]); ?>
        <?= $form->field($model, 'id')->hiddenInput()->label(false) ?>

        <div class="col-lg-12">                
            <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-lg-5">
            <?= $form->field($model, 'users')->dropDownList(ArrayHelper::map(\app\models\Employees::find()->orderBy('name')->all(),'id','name'), 
                     ['prompt'=>'Select User','id'=>'users']);?>
        </div>  
        <div class="col-lg-5">                
            <?= $form->field($model, 'role')->dropDownList(ArrayHelper::map(\app\models\Roles::find()->orderBy('name')->all(),'id','name'), 
                     ['prompt'=>'Select Role','id'=>'role']);?>
        </div>            
        <div class="col-lg-12">
            <?= $form->field($model, 'synopsis')->textarea(['rows' => 6]) ?>
        </div>
        <div class="col-lg-12">                
            <?= $form->field($model, 'poster[]')->fileInput(['multiple' => true, 'accept' => 'image/*','class'=>'form-control']) ?>               
        </div>
        <div class="col-lg-12">               
            <?=$form->field($model, 'promo[]')->fileInput(['multiple' => true,'class'=>'form-control'])?>                        
        </div>
        <div class="col-lg-2">
            <?=Html::a('Cancel',['/project/index'],['class' => 'btn form-control','style' => 'background-color:#a6a6a6;color:black']) ?>
        </div>
        <div class="col-lg-8"></div>
        <div class="col-lg-2">
            <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success form-control' : 'btn btn-primary form-control']) ?>
        </div>


        <?php ActiveForm::end(); ?> 

请有人帮我做 提前致谢

0 个答案:

没有答案