1
我创建了一个DynamicModel来构建一个包含checkboxList的搜索表单,其中的项目由模型的记录填充。表单工作正常,但表单显示在结果页面上,并且所有字段都使用除checkboxList之外的先前选定的值填充。使用DynamicModel问题的checkboxList的预填充
控制器:
$model = DynamicModel::validateData(
['date_from',
'date_to',
'client_site',
'report_types',
]);
$model->addRule(['client_site'], 'integer');
$model->addRule(['client_site', 'report_types'], 'required');
$model->addRule(['date_from','date_to'], 'string');
$model->load(Yii::$app->request->post()) && $model->validate();
$reportTypes = ArrayHelper::map(ReportType::find()->asArray()->all, 'id', 'name');
return $this->render('print-report-form', [
'report_types' => $reportTypes,
'model' => $model,
]);
查看:
<?= $form->field($model, 'report_types[]')
->inline(false)
->checkboxList($reportTypes);
?>
我需要扳平$ reportTypes在模型中的另一种方式?关于为什么选择的复选框未在表单提交中预填充的任何想法?
非常感谢你的回应。我可以通过从表单中的'report_types []'中删除''''来解决它。从文件传递到文件时,变量名称应该没有关系。克隆模型也是不必要的,但我很感激。我很迷茫。谢谢 – Dubby