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'
順便說一句,我的形式不是填充請求數據。