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()
接受。
什麼了我做錯了什麼?