Zend框架2回调过滤器

时间:2014-07-09 16:24:55

标签: php zend-framework2

在ZF2中,是否可以将表单值数组传递给类似于回调验证器的回调过滤器?

//Validator callback works
'callback' => function($value, $context){
  //$context contains form values
}

//Need similar functionality for filter
'callback' => function($value, $context){
  //$context will issue a warning because its not set
}

//I know the following filter works, but I dont know how to pass the form
'callback' => function($value, $context){
  print_r($context); //Prints 'hello world'
},
'options' => array(
  'callback_params' => array(
    'context' => 'hello world' //I need this to be the form values
  )
)

1 个答案:

答案 0 :(得分:1)

InputFilter没有您想要的,但您可以使用use将Form对象传递给回调并从输入过滤器获取原始表单值

$form = $this;

'callback' => function($value) use ($form) {
  var_dump($form->getInputFilter()->getRawValues());
}