Zend框架2回调过滤器(Zend framework 2 callback filter)

2019-10-20 10:31发布

在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
  )
)

Answer 1:

输入过滤器没有你想要的东西,但是你可以通过使用Form对象到回调use ,并从输入滤波器的原始形式值

$form = $this;

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


文章来源: Zend framework 2 callback filter