2015-01-30 8 views

답변

1

몇 가지 포인트가 사소한 조작을 필요로

$inputFilter->add($factory->createInput(array(
      'name'  => 'codigo', 
      'required' => true, 
      'validators' => array(
       array(
        'name' => 'not_empty', 
       ), 
      ), 
      'filters' => array(
       array(
        'name' => 'Alnum', 
        'allowwhitespace' => false, 
       ), 
      ), 
     ))); 
;

  • ValidatorPluginManager 수단 cannonical 이름으로 검사기를 호출 정규화 별칭을 사용 'not_empty'는 유효한 별명 아니며, 그것은 '는 NotEmpty'또는 '는 NotEmpty'이어야한다.
  • Alnum 필터 서명이 유효하지 않은 것으로 보입니다. 하위 키 options 내부에 추가 옵션을 제공해야합니다.

이 시도 (예, 이것은 정말 이상한 모순이다) :

$filter = new \Zend\InputFilter\InputFilter(); 
$filter->add(array(
      'name'  => 'codigo', 
      'required' => true, 
      'validators' => array(
       array(
        'name' => 'NotEmpty', 
       ), 
      ), 
      'filters' => array(
       array(
        'name'    => 'Alnum', 
        'options'   => array(
         'allow_white_space' => false, 
        ) 
       ), 
      ), 
     )); 

$filter->setData(['codigo' => 'Whitespace exists']); 
if($filter->isValid() === false) { 
    // You'll fall here with a value like multiple spaces etc.. 
    var_dump($filter->getMessages()); 
} else { 
    var_dump($filter->getValues()); // Prints ['codigo' => string 'Whitespaceexists'] 
}