Zend 框架自定义验证类 [英] zend framework custom validation classes
问题描述
我正在编写一个自定义验证器,用于检查电子邮件是否存在,如果它已存在于数据库中,则表单无效.我很难为自定义 Zend_Validation 类找出帮助器路径和命名空间.
我想调用类 My_Validate_EmailUnique 但我不断收到错误消息,例如:有一个错误异常 'Zend_Loader_PluginLoader_Exception' 与消息 'Plugin by name 'My_Validate_EmailUnique' 在注册表中未找到;使用的路径:My_Validate_:/var/www/site/arc/helpers/
类看起来像这样:
有人可以帮助我注册 Zend_Form 以查找自定义验证器的位置吗?
您可以直接将验证器添加到表单元素中.无需为此编写自定义验证器.
在您的表单中:
<预><代码>$element->addValidator(new Zend_Validate_Db_NoRecordExists('mytablename', 'myemailcolumnname'));I'm writing a custom validator that is going to check for the existence of an email such that if it already exists in the database, the form is not valid. I'm having a hard time figuring out helper paths and namespaces for custom Zend_Validation classes.
I'd like to call the class My_Validate_EmailUnique but I keep getting error messages such as: there is an error exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'My_Validate_EmailUnique' was not found in the registry; used paths: My_Validate_: /var/www/site/arc/helpers/
The class looks like this:
<?php
class My_Validate_EmailUnique extends Zend_Validate_Abstract
{
const EMAIL_UNIQUE = 'notMatch';
Can someone help me with where I register for the Zend_Form to look for custom validators?
You can directly add the validator to your form element. There is no need to write a custom validator for this.
In your form:
$element->addValidator(new Zend_Validate_Db_NoRecordExists('mytablename', 'myemailcolumnname'));
这篇关于Zend 框架自定义验证类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!