2014-04-01 28 views
2

當以我Zend框架2 Form類驗證未添加到鏈,添加我元件像這樣:使用數組語法

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

這僅僅是如在official reference說明。我創建窗體的新實例,像這樣:

$form = $this->getServiceLocator()->get('user.auth.form'); 
    $hydrator = new DoctrineHydrator($this->entityManager()); 
    $form->setHydrator($hydrator); 
    $form->bind($user); 

然而,validators沒有被添加到元素校驗器鏈。這裏是var_dump($form->get('passwordConfirm'));

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()接受。

什麼了我做錯了什麼?

回答

0

尋找到的源和這個語法我發現你根本無法使用這個數組語法的Zend Framework 2.3的加驗證嘗試一些其他的事情後。從官方文檔上面我引用的例子是完全錯誤的。

對於驗證,可以使用在參考上Zend\Validator在部分中描述的更詳細的語法。