dongpian2559 2018-10-22 15:16
浏览 54
已采纳

检查哪个表单字段值已更改Symfony 3

I need to check inside the FormType which field has changed. Is there any method to do it? I've searched for a while, then tried to get edited entities field in few ways (with form events too) to catch the edited fields, but no simple result.

Is there any way to do it easy, or I need to be more creative in making such thing? The best it would be, if I can get an example with entity type, but any clue would be great.

P.S. I cant do it on client-side - I must do it on server side for particular reason.

  • 写回答

1条回答 默认 最新

  • doutale7115 2018-10-22 16:47
    关注

    Done with this: https://stackoverflow.com/a/33923626/8732955

    Suppose we want to check the "status" field in our ImportantObject, code needs to look like that

    if($form->isSubmitted() && $form->isValid())
    {
            $uow = $em->getUnitOfWork();
            $uow->computeChangeSets();
            $changeSet = $uow->getEntityChangeSet($importantObject);
    
            if(isset($changeSet['status'])){
              //do something with that knowledge
            }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突