1 回答

TA貢獻2080條經驗 獲得超4個贊
您可以在驗證上傳遞該選項。message
App\Entity\User:
properties:
plainPassword:
- Symfony\Component\Validator\Constraints\NotCompromisedPassword:
message: "You error message"
但是,如果要將約束驗證為驗證器,則可以使用:
class MyValidator extends ConstraintValidator
{
public function validate($value, Constraint $chain)
{
// Previous check...
$groups = $this->context->getGroup();
$violations = $this->context->getViolations();
$current = $violations->count();
// Execute the new constraint
$this->context->getValidator()
->inContext($this->context)
->validate($value, new MyOtherConstraint(), $groups);
// Check if the constraint has failed
if ($violations->count() !== $current) {
return;
}
}
}
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報