0
我试图用以下方式更新我的实体与Symfony 2的表单类型实体。我使用jsonrpc协议JSON数据发送到服务器端用表单类型实体提交表单symfony2
public functionUpdatMethod($params)
{
$user = $this->em->getRepository("Repository:User")->find($id);
$form = $this->formFactory->createBuilder(UserType::class, $user)->getForm();
$data = $this->requestStack->getCurrentRequest();
$form->submit(json_decode($data, true));
$form->isValid()
if($form->isValid()) { // return true
try {
$this->em->flush();
return "ok";
} catch (\Exception $e) {
dump($e->getMessage());
exit();
}
}
}
isValid
方法返回true,但我得到了以下错误:
Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'UNIQ_8D93D6495126AC48'
顺便说一句,我的形式不是填充请求数据。