Zend Form自定义验证路径问题 [英] Zend Form Custom Validation Path issues

查看:86
本文介绍了Zend Form自定义验证路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

找不到名称为垃圾邮件"的插件 注册表;使用的路径: Zend_Validate_:Zend/Validate/

Plugin by name 'Spam' was not found in the registry; used paths: Zend_Validate_: Zend/Validate/

我在bootstrap.php文件中有此文件(这不是一个类):

I have this on my bootstrap.php file (it's NOT a class):

include_once 'config_root.php';
set_include_path ( $PATH );

require_once 'Initializer.php';
require_once "Zend/Loader.php";
require_once 'Zend/Loader/Autoloader.php';

// Set up autoload.
$loader = Zend_Loader_Autoloader::getInstance ();
$loader->setFallbackAutoloader ( true );
$loader->suppressNotFoundWarnings ( false );

//resource Loader
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
                'basePath' => APPLICATION_PATH,
                'namespace' => '',
            ));

$resourceLoader->addResourceType('validate', 'validators/', 'My_Validate_');

$loader->pushAutoloader($resourceLoader);

我已经这样命名了一个名为Spam.php的文件:

I've named a file called Spam.php like this:

application/validators/Spam.php

class My_Validate_Spam extends Zend_Validate_Abstract {

在表单类上,我有:

//HONEY POT
        $this->addElement(
                'text', 'honeypot', array(
                    'label' => 'Honeypot',
                    'required' => false,
                    'class' => 'honeypot',
                    'decorators' => array('ViewHelper'),
                    'validators' => array(
                        array(
                            'validate' => 'Spam'
                        )
                    )
                )
        );

有了这些,我得到了:

找不到名称为垃圾邮件"的插件 注册表;使用的路径: Zend_Validate_:Zend/Validate/

Plugin by name 'Spam' was not found in the registry; used paths: Zend_Validate_: Zend/Validate/

为什么?

非常感谢.

推荐答案

您必须将具有自定义验证器的目录添加到表单元素前缀路径.例如:

You have to add the directory where you have your custom validators to your form elements prefix path. For example:

$elementPrefixPaths = 
    array(
        array(
            array(
                'prefix' => 'My_Validate_', 
                'path' => 'My/Validate', // 'application/validators' in your case
                'type' => 'validate',
            )
        )
    );
$form->addElementPrefixPaths($elementPrefixPaths);
// or, if your're inside the form, 
// $this->addElementPrefixPaths($elementPrefixPaths)
// before any elements make use of the validator.

路径"应位于您的包含路径中.您必须对自定义过滤器执行相同的操作.对于自定义装饰器和元素(也使用setPrefixPaths()方法)也有类似的方法.

The 'path' should be in your include path. You have to do the same with your custom filters. Also there is a similar approach for custom decorators and elements (which use the method setPrefixPaths() instead).

此处.

您的路径是应用程序/验证器",但最好在类命名和路径镜像上遵循ZF约定;因此,您应该将验证器放在我的/验证"之类的目录中,并且应该对开发的所有自定义ZF扩展(过滤器,帮助器,插件等)都遵循此约定.从长远来看,它将使您的生活更轻松.另外,作为最后的建议,请勿使用"My_"作为您的班级前缀,而应使用更个人化的名称,例如"Mem _"(考虑您的昵称).

Your path is 'application/validators', but it would be better to follow ZF convention on class naming and path mirroring; as such you should put your validator in a directory such as 'My/Validate' You should follow this convention on all custom ZF extensions you develop (filters, helpers, plugins, etc). It will make your life easier in the long run. Also, as a final suggestion, don't use "My_" as your classes prefix, use something more personal, such as "Mem_" (considering your nickname).

这篇关于Zend Form自定义验证路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆