两个sfValidatorDoctrineUnique在同一表格上?

时间:2012-06-21 14:14:45

标签: php symfony1 symfony-forms

我有一个symfony表单,想在postVlidator中对字段(Fname,Lname)进行两次唯一验证

$this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique
                                                     (
                                                        array( 'model' => 'Test',
                                                               'column' => array('fName'),
                                                      , array('invalid' => 'Invalid fName')));

$this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique
                                                     (
                                                        array( 'model' => 'Test',
                                                               'column' => array('Lname'),
                                                      , array('invalid' => 'Invalid Lname')));

当我这样做时,第二个覆盖第一个......错误在哪里?

1 个答案:

答案 0 :(得分:1)

您必须在同一个setPostValidator的调用中将它们组合在一起。例如:

$this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
  new sfValidatorSchemaCompare('start_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'end_date'),
  new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again'),
)));

它在the doc中(向上滚动一下以查看示例)。