【问题标题】:Submit form with form type entity symfony2提交表单类型实体 symfony2 的表单
【发布时间】:2016-04-03 14:45:45
【问题描述】:

我尝试通过以下方式使用 Symfony 2 的表单类型实体更新我的实体。我正在使用 jsonrpc 协议将 json 数据发送到服务器端

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,但出现以下错误:

错误:SQLSTATE[23000]:完整性约束违规:1062 键“UNIQ_8D93D6495126AC48”的重复条目

顺便说一句,我的表单没有填充请求数据。

【问题讨论】:

    标签: api symfony


    【解决方案1】:

    消息错误是否表明,您的数据库约束违反了表单验证。看起来您尝试第二次记录标有唯一键的字段。

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2013-07-09
      相关资源
      最近更新 更多