我想将Symfony Form用于验证目的。所以我用实体填充实体:
$reductionCalculator = new ReductionCalculator();
$reductionCalculator->setClaim($claim);
$reductionCalculator->setDecreasedCapital($decreasedCapital);
$reductionCalculator->setCredit($credit);
然后创建表单:
$form = $this->createForm(ReductionCalculatorType::class);
我尝试提交数据:
$form->submit($reductionCalculator);
//or
// $form->setData($reductionCalculator);
并验证:
if (!$form->isValid()) {
$this->throwApiProblemValidationException($form);
}
但这会抛出异常:
"不能使用AppBundle \ Entity \ ReductionCalculator类型的对象作为 阵列"
如何在不将对象更改为数组的情况下执行此操作。也许其他Form方法比submit()
?