Zend framework 2 callback filter

核能气质少年 提交于 2019-12-11 08:47:34

问题


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:


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());
}


来源:https://stackoverflow.com/questions/24659019/zend-framework-2-callback-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!