php – Symfony2中不推荐使用的方法addValidation和类CallbackValidator

前端之家收集整理的这篇文章主要介绍了php – Symfony2中不推荐使用的方法addValidation和类CallbackValidator前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有个问题.我需要在表单类型类中验证不在实体中的字段.以前我用过这段代码
$builder->addValidator(new CallbackValidator(function(FormInterface $form){
    if (!$form['t_and_c']->getData()) {
        $form->addError(new FormError('Please accept the terms and conditions in order to registe'));
    }
}))

但是,因为不推荐使用Symfony 2.1方法addValidator和类CallbackValidator.有谁知道我应该用什么呢?

我这样做了:
add('t_and_c','checkBox',array(
            'property_path' => false,'constraints' => new True(array('message' => 'Please accept the terms and conditions in order to register')),'label' => 'I agree'))

猜你在找的PHP相关文章