在一个 ActiveForm 中更新多个模型数据
Updating several model data at one ActiveForm
有可能通过post这样的请求来更新或获取数据吗?
$jobs = Jobs::find()->select(['name'])->all();
<?php $form = ActiveForm::begin([
'action' => ['document/generator?id='],
'id' => 'doc_form',
]);?>
<?php for($i=0; $i<count($jobs);$i++):?>
<?= $form->field($jobs[$i], 'name')->textInput(['maxlength' => true]) ?>
<?php endfor;?>
<div class="form-group text-right">
<?= Html::submitButton('Jo\'natish', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end();?>
我为什么要问这个?
HTML name, id 属性具有相同、相似的值。
您可以在选项数组中指定一个正确的 id asssing 正确的值
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activeform#field()-detail
<?= $form->field($jobs[$i], 'name', [
'id'=> 'job-name-'.$i,
])->textInput(['maxlength' => true]) ?>
您可以像下面这样使用Collecting tabular input:
$form = ActiveForm::begin();
foreach ($settings as $index => $setting) {
echo $form->field($setting, "[$index]value")->label($setting->name);
}
ActiveForm::end();
有可能通过post这样的请求来更新或获取数据吗?
$jobs = Jobs::find()->select(['name'])->all();
<?php $form = ActiveForm::begin([
'action' => ['document/generator?id='],
'id' => 'doc_form',
]);?>
<?php for($i=0; $i<count($jobs);$i++):?>
<?= $form->field($jobs[$i], 'name')->textInput(['maxlength' => true]) ?>
<?php endfor;?>
<div class="form-group text-right">
<?= Html::submitButton('Jo\'natish', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end();?>
我为什么要问这个?
HTML name, id 属性具有相同、相似的值。
您可以在选项数组中指定一个正确的 id asssing 正确的值
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activeform#field()-detail
<?= $form->field($jobs[$i], 'name', [
'id'=> 'job-name-'.$i,
])->textInput(['maxlength' => true]) ?>
您可以像下面这样使用Collecting tabular input:
$form = ActiveForm::begin();
foreach ($settings as $index => $setting) {
echo $form->field($setting, "[$index]value")->label($setting->name);
}
ActiveForm::end();