问题
I am using the password confirmation validator from the official Zend framwork document here:
http://framework.zend.com/manual/en/zend.form.elements.html
In Bootstrap.php, I have set the namespace as
'namespace' => 'My_'
The file is located at application/validate/PasswordConfirmation.php
However, "Fatal error: Class 'My_Validate_PasswordConfirmation' not found" occurs in my Zend_Form.
What should I do to fix the problem?
回答1:
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:
- Name the class 
My_Validate_PasswordConfirmation - Put it in `application/My/Validate/PasswordConfirmation.php
 - Add 
namespace=>'My_Validate'to yourZend_Filter_Inputoptions. - Invoke the validator as simply "PasswordConfirmation".
 
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.
Here's another clue:
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.
So try this:
'namespace' => 'My',
with no trailing underscore.
来源:https://stackoverflow.com/questions/1010265/where-should-my-validate-passwordconfirmation-put-in-zend-framework