首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用数组语法时,验证器没有添加到链中

当使用数组语法时,验证器没有添加到链中
EN

Stack Overflow用户
提问于 2014-04-01 13:34:54
回答 1查看 172关注 0票数 2

在ZendFramework2Form类中,我添加了如下元素:

代码语言:javascript
复制
    $this->add(array(
        'name' => 'passwordConfirm',
        'type' => 'Password',
        'attributes' => array(
            'required' => 'required',
            'placeholder' => 'Confirm password',
        ),
        'options' => array(
            'label' => 'Confirm password',
            'column-size' => 'sm-10',
            'label_attributes' => array(
                'class' => 'col-sm-2',
            ),
        ),
        'validators' => array(
            array(
                'name' => 'NotEmpty',
            ),
            array(
                'name' => 'Identical',
                'options' => array(
                    'token' => 'password',
                ),
            ),
        ),
    ));

正如正式参考中所描述的那样。我创建了一个新的表单实例,如下所示:

代码语言:javascript
复制
    $form = $this->getServiceLocator()->get('user.auth.form');
    $hydrator = new DoctrineHydrator($this->entityManager());
    $form->setHydrator($hydrator);
    $form->bind($user);

但是,validators没有添加到元素验证器链中。这是var_dump($form->get('passwordConfirm'));的输出

代码语言:javascript
复制
object(Zend\InputFilter\Input)[506]
  protected 'allowEmpty' => boolean true
  protected 'continueIfEmpty' => boolean false
  protected 'breakOnFailure' => boolean false
  protected 'errorMessage' => null
  protected 'filterChain' => 
    object(Zend\Filter\FilterChain)[507]
       protected 'plugins' => null
       protected 'filters' => 
        object(Zend\Stdlib\PriorityQueue)[508]
          protected 'queueClass' => string 'Zend\Stdlib\SplPriorityQueue' (length=28)
          protected 'items' => 
            array (size=0)
              ...
          protected 'queue' => null
      protected 'options' => 
         array (size=0)
           empty
   protected 'name' => string 'passwordConfirm' (length=15)
   protected 'notEmptyValidator' => boolean false
   protected 'required' => boolean false
   protected 'validatorChain' => 
     object(Zend\Validator\ValidatorChain)[509]
      protected 'plugins' => null
      protected 'validators' => 
        array (size=0)
          empty
      protected 'messages' => 
        array (size=0)
          empty
  protected 'value' => null
  protected 'fallbackValue' => null
  protected 'hasFallback' => boolean false

当我为验证器输入无效的输入时,表单将被$form->isValid()接受,而不会出现问题。

我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-14 08:06:33

在查看了源代码并使用此语法尝试了一些其他内容之后,我发现您无法在ZendFramework2.3中使用此数组语法添加验证器。我上面引用的正式文档中的例子完全是错误的。

为了进行验证,请使用引用中关于Zend\Validator的部分中描述的更详细的语法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22787564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档