在Symfony中为sfValidatorOr添加错误


add error for sfValidatorOr in Symfony

我有:

$this->validatorSchema->setPostValidator(new sfValidatorOr(
  array(
    new sfValidatorSchemaCompare('email', '!=', ''),
    new sfValidatorSchemaCompare('phone', '!=', ''),
  ),
  array(),
  array('invalid' => 'Campo obligatorio')
));

错误在$form->getGlobalErrors()中。如何添加

阵列("throw_global_error"=> true),

和这里一样:

$this->validatorSchema->setPostValidator(
  new sfValidatorOr(
    array(
      new sfValidatorAnd( 
        array(
          new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::EQUAL, 'date_to',
            array('throw_global_error' => true),
            array('invalid' => 'The start date ("%left_field%") must be equal the end date ("%right_field%")')),
          new sfValidatorSchemaCompare('time_from', sfValidatorSchemaCompare::LESS_THAN, 'time_to',
            array('throw_global_error' => true),
            array('invalid' => 'The start time ("%left_field%") must be before the end time ("%right_field%")')),
       )),
          new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::LESS_THAN, 'date_to',
            array('throw_global_error' => true),
            array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")')),
    )
  ));

?

我将渲染这个:

<?php $form['email']->renderLabel() ?>
**<?php echo $form['email']->getError() ?>** 

但是在sfValidatorOr中这不起作用

你可以把throw_global_error选项直接放在sfvalidatorschemaccompare()上。

没有办法把它放在sfValidatorOr上,因为它不是sfValidatorSchema对象。