Building Symfony 2 Custom Validator that Uses Multiple Fields

前端 未结 2 1842
野趣味
野趣味 2021-02-04 03:41

I\'m building a custom validator that needs to validate the value from TWO form fields in the db in order to get this constraint to pass.

My question is this: the Contra

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 04:07

    Any custom validator that extends ConstraintValidator has access to the $context property. $context is an instance of ExecutionContext that gives you access to submitted data:

    Example:

    context->getRoot()->getData();
            /* ... */
        }
    }
    

提交回复
热议问题