Zend 框架 2 回调过滤器 [英] Zend framework 2 callback filter
本文介绍了Zend 框架 2 回调过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ZF2 中,是否可以将表单值数组传递给类似于回调验证器的回调过滤器?
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
)
)
推荐答案
InputFilter 没有你想要的,但是你可以使用 use
将 Form 对象传递给你的回调并获取原始表单来自输入过滤器的值
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());
}
这篇关于Zend 框架 2 回调过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文