0

我有一个 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')));

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

4

1 回答 1

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'),
)));

它在文档中(滚动到顶部以查看示例)。

于 2012-06-21T14:20:06.333 回答