Zend framework 2 callback filter

2019-08-01 08:01发布

In ZF2, is it possible to pass form values array to the callback filter similar to the callback validator?

//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条回答
看我几分像从前
2楼-- · 2019-08-01 08:30

InputFilter doesn't have what you want, But you can pass the Form object to your callback using use and get the raw form values from input filter

$form = $this;

'callback' => function($value) use ($form) {
  var_dump($form->getInputFilter()->getRawValues());
}
查看更多
登录 后发表回答