Symfony2 Form Validator - Comparing old and new values before flush

前端 未结 4 623
暗喜
暗喜 2021-02-05 10:40

I was wondering if there is a way to compare old and new values in a validator within an entity prior to a flush.

I have a Server entity which renders to a

4条回答
  •  春和景丽
    2021-02-05 11:09

    Previous answers are perfectly valid, and may fit your use case.

    For "simple" use case, it may fill heavy though. In the case of an entity editable through (only) a form, you can simply add the constraint on the FormBuilder:

    add('fooField', IntegerType::class, [
                    'constraints' => [
                        new GreaterThanOrEqual(['value' => $builder->getData()->getFooField()])
                    ]
                ])
            ;
        }
    }
    

    This is valid for any Symfony 2+ version.

提交回复
热议问题