我只想使用Symfony表单进行验证。所以我用数据填充实体:
$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类型的对象用作数组”
如何在不将对象更改为数组的情况下正确执行此操作。可能是submit()
之外的其他表单方法
https://stackoverflow.com/questions/50684997
复制相似问题