简体   繁体   English

在Zend 2中注册自定义验证器

[英]Registering a custom validator in Zend 2

I create a custom date Validator. 我创建一个自定义的日期验证器。 But I keep getting this error message : 但我不断收到此错误消息

"Zend\\Validator\\ValidatorPluginManager::get was unable to fetch or create an instance for date_validator" “ Zend \\ Validator \\ ValidatorPluginManager :: get无法获取或为date_validator创建实例”

I did some research and tried adding in module.config.php after the view manager array. 我做了一些研究,并尝试在视图管理器数组之后添加module.config.php

'validators' => array(
    'invokables' => array(
        'date_validator' => 'Administrativo\InputFilter\Date_Validator'
    ),
),

What am I missing here? 我在这里想念什么?

Your configuration seems okay. 您的配置似乎还可以。

Are you sure you have a file (invokable class) with the name Date_Validator in a folder Administrativo\\InputFilter in your module? 您确定模块中的文件夹Administrativo\\InputFilter中有一个名为Date_Validator的文件(可调用类)吗?

Is the namespace inside this class Administrativo\\InputFilter and is the class name Date_Validator . 是此类Administrativo\\InputFilter的名称空间,并且是类名称Date_Validator

It is important that both the class name and namespace have to be correct as well as the folder names and file name . 重要的是, 类名名称空间以及文件夹名文件名都必须正确。 Otherwise the PluginManager will not be able to find your file. 否则,PluginManager将无法找到您的文件。


UPDATE UPDATE

If all that is fine then there is something else you should check. 如果一切正常,那么您还应该检查其他内容。

If you build your input filters through config array then you should make sure that the factory inside your InputFilter class holds a correctly populated InputFilterPluginManager instance (with both ValidatorManager and FilterManager on board). 如果通过config数组构建输入过滤器,则应确保InputFilter内部的工厂拥有正确填充的InputFilterPluginManager实例(同时包含ValidatorManagerFilterManager )。 Otherwise it will not inject those classes in the setInputFilterManager method and it will later create a new empty plugin manager instance which will obviously not hold your validator class. 否则,它将不会在setInputFilterManager方法中注入这些类,并且稍后创建一个新的空插件管理器实例 ,该实例显然将不包含您的验证器类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM