在servicemanager config zend框架中设置自定义过滤器插件 [英] Set custom filter plugin inside servicemanager config zend framework
问题描述
我的应用程序用户窗体中有以下代码,用于为address2 element
创建输入过滤器.
I have the following code in my application user form that creates the input filter for the address2 element
.
$inputFilter = new InputFilter();
$inputFilter->add([
'name' => 'address2',
'required' => true,
'filters' => [
['name'=>'StringTrim'],
['name'=>'Administration\Filter\Ucwords']
]
]);
如您所见,我将类名设置为过滤器的名称.
As you can see, I have the class name set as the name of the filter.
我收到以下错误:
A plugin by the name "Administration\Filter\Ucwords" was not found in the plugin manager Zend\Filter\FilterPluginManager
.
如何将此过滤器放入servicemanager configuration
?
注意
我想使用配置设置此设置,而不是从模块类内部执行调用,因此我可以说Ucwords
而不是过滤器配置中的完整类名.
I want to set this using configuration, not executing a call from within the module class so I can say Ucwords
instead of the full class name inside the filter config.
推荐答案
该配置对我来说是正确的.唯一的问题是,您在指定过滤器名称(Administration\Filter\Ucwords
)时犯了错字错误.确保该类存在并且可以自动加载.
The configuration looks correct to me. The only issue here is that you have made a typo error when specifying filter name (Administration\Filter\Ucwords
). Make sure that such class exists and it can be autoloaded.
我也强烈建议您指定类常量(用于完全限定的类名解析)而不是字符串,例如
I also strongly suggest you to specify the class constant (for fully qualified class name resolution) instead of string, e.g.
...
['name' => Administration\Filter\Ucwords::class]
...
这篇关于在servicemanager config zend框架中设置自定义过滤器插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!