gpt4 book ai didi

validation - symfony2 2.3 缺少FormBuilder::addValidator() 如何适配FormBuilderInterface?

转载 作者:行者123 更新时间:2023-12-04 02:44:59 25 4
gpt4 key购买 nike

好像FormBuilder的addValidator函数在symfony2的最新版本中没有了。任何人都知道如何重写该功能?

这是我的 2.0 代码:

    $builder-> addValidator(new CallbackValidator(function(FormInterface $form){
$email = $form->get('email')->getData();
if (empty( $email )) {
$form['email']->addError(new FormError("Du måste ange en epostadress för användaren"));
}
}));

我知道 FormBuilder 在 2.1 中已被“FormBuilderInterface”取代,但我仍然对重写此功能需要采取哪些步骤感到困惑。

最佳答案

自从 Symfony 2.1 以来,由 CallbackValidator 实现的 FormValidatorInterface 已被弃用,并在 2.3 中删除。

Upgrade to 2.1 file给出解决方案:

The interface FormValidatorInterface was deprecated and will be removed in Symfony 2.3.

If you implemented custom validators using this interface, you can substitute them by event listeners listening to the FormEvents::POST_BIND (or any other of the *BIND events). In case you used the CallbackValidator class, you should now pass the callback directly to addEventListener.

关于validation - symfony2 2.3 缺少FormBuilder::addValidator() 如何适配FormBuilderInterface?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com