views:

480

answers:

1

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?

+2  A: 

Hi, 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 your Zend_Filter_Input options.
  • 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.

Bill Karwin
In the official quickstart tutorial, Default_Form_Guestbook is placed under application/forms/Guestbook.php and Default_Model_Guestbook is placed under application/models/Guestbook.php. It makes me feel that I should follow the folder structure like that.How can I add namespace=>'My_Validate' to your Zend_Filter_Input options?I read this tutorial:http://zfsite.andreinikolov.com/2008/05/part-4-zend_form-captcha-password-confirmation-date-selector-field-zend_translate/Will you suggest me putting the custom validator under library folder? Do I have to "addPrefix" or others to make it work?
Billy
Thanks a lot. I add the passwordconfirmation to the form successfully.You are the only one that can solve my problem.I am suprised that I can't find any tutorial teaching me to set the resourceTypes in autoloader(I didn't know about resourceTypes before) to use custom validators. It can be done easily, but I don't think a newbie can realize and find a solution to fix the problem.
Billy
I think ZF has become too complex. They have so many points of configuration possible, but they don't give enough documentation or sensible defaults to guide new users. It's gotten out of hand.
Bill Karwin