【问题标题】:Is it possible to define more than one post-validator in Symfony?是否可以在 Symfony 中定义多个后验证器?
【发布时间】:2011-10-05 15:24:30
【问题描述】:

我需要在 Symfony 表单中执行几个后验证。我第一次遇到这个问题时,我写了这个:

$this->validatorSchema->setPostValidator(
  new sfValidatorCallback(array(
    'callback' => array($this, 'checkStatusHasMethod'))
));

因为我只想检查某种情况。

但是随着应用程序的增长,我现在需要执行额外的检查。我想用不同的方法隔离每个验证,而不是使用一个大的 checkX 方法将所有东西放在一起。

是否可以将sfPostValidator 与多个方法关联或在validatorSchema 中创建多个sfPostValidator 实例?

谢谢!

【问题讨论】:

    标签: php forms validation symfony-1.4


    【解决方案1】:

    试试 mergePostValidator() (或类似的,不记得确切的方法名称)

    【讨论】:

      【解决方案2】:

      据我所知,有一个名为 sfValidatorAnd() 的验证器可以让你这样做。

      编辑:你可以这样做:

      new sfValidatorAnd(
          array(
              new sfValidatorString(),
              new sfValidatorRegex(),
          )
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 2015-03-01
        • 2012-05-05
        • 2022-11-08
        • 1970-01-01
        相关资源
        最近更新 更多