My_Validate_PasswordConfirmation 应该放在 Zend 框架的什么位置? [英] Where should My_Validate_PasswordConfirmation put in Zend framework?
问题描述
我在这里使用来自官方 Zend 框架文档的密码确认验证器:
http://framework.zend.com/manual/en/zend.form.elements.html
I am using the password confirmation validator from the official Zend framwork document here:
http://framework.zend.com/manual/en/zend.form.elements.html
在 Bootstrap.php 中,我将命名空间设置为
'命名空间' => 'My_'
In Bootstrap.php, I have set the namespace as
'namespace' => 'My_'
文件位于应用程序/验证/密码确认.php
The file is located at application/validate/PasswordConfirmation.php
但是,致命错误:未找到类‘My_Validate_PasswordConfirmation’"出现在我的 Zend_Form 中.
However, "Fatal error: Class 'My_Validate_PasswordConfirmation' not found" occurs in my Zend_Form.
我应该怎么做才能解决问题?
What should I do to fix the problem?
推荐答案
我设计并实现了 Zend_Filter_Input
,包括它的命名空间特性.
I designed and implemented Zend_Filter_Input
, including its namespace feature.
您对这个功能的工作原理有一个倒退的理解.它旨在允许您在验证器类的实际名称较长时使用短名称.您显然在做相反的事情,试图用比实际名称更长的名称命名一个类.
You have a backwards understanding of how this feature works. It's meant to allow you to use a short name for a validator class when the actual name of that class is longer. You're apparently doing the reverse, trying to name a class with a longer name than it actually has.
要解决此问题,我建议执行以下步骤:
To fix this I recommend the following steps:
- 为类命名
My_Validate_PasswordConfirmation
- 把它放在`application/My/Validate/PasswordConfirmation.php
- 将
namespace=>'My_Validate'
添加到您的Zend_Filter_Input
选项. - 以PasswordConfirmation"的形式调用验证器.
- Name the class
My_Validate_PasswordConfirmation
- Put it in `application/My/Validate/PasswordConfirmation.php
- Add
namespace=>'My_Validate'
to yourZend_Filter_Input
options. - Invoke the validator as simply "PasswordConfirmation".
更新:我花了一些时间在这上面.看来我的第一个想法偏离了目标.您的命名空间问题与 Zend_Filter_Input
的功能无关,它与 Zend_Application
引导功能有关.似乎您可以为自动加载器指定一个类前缀.
update: I spent some time on this. It seems my first idea was off target. The namespace issue you have has nothing to do with the feature of Zend_Filter_Input
, it has to do with the Zend_Application
bootstrap feature. It seems that you can specify a class prefix to the autoloader.
这是另一个线索:
Zend_Loader_Autoloader_Resource 使假设您是所有代码自动加载将使用下划线命名空间之间的分隔符,组件和类.其结果,你不需要使用尾随注册资源时下划线自动加载器.
Zend_Loader_Autoloader_Resource makes the assumption that all code you are autoloading will use an underscore separator between namespaces, components, and classes. As a result, you do not need to use the trailing underscore when registering a resource autoloader.
试试这个:
'namespace' => 'My',
没有尾随下划线.
这篇关于My_Validate_PasswordConfirmation 应该放在 Zend 框架的什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!