1

Do I need to save my custom Zend Validator location to "Zend/Validate"? I'd rather create a folder for all my custom validation scripts, but cannot find anything in the Zend documentation other than changing the namespace.

Here is my error message.

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

I'd like to tell it to search additional paths.

Charles
  • 50,943
  • 13
  • 104
  • 142
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159

3 Answers3

2

I was able to solve my problem using

addElementPrefixPath('Application_Validate',
                                    '../application/validate',
                                    'validate');
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
1

Did you check the API docs? Zend_Validate has an addDefaultNamespaces method...

public static function addDefaultNamespaces($namespace){
Cobby
  • 5,273
  • 4
  • 28
  • 41
  • I was under the impression that changing the namespace allows you to change the prefix of your class from "Zend_Validate" to something else, but not the location. addDefaultNamespaces takes only one argument, which leads me to believe my assumption is true? – Martin Konecny Feb 09 '11 at 04:44
  • Changing the namespace should automatically map to the file system. If you add "My_Validators" then it will look for those validators in My/Validators. – Cobby Feb 09 '11 at 04:49
1

I usually keep my custom validators (e.g. My_Validate_Age) in APPLICATION_PATH/validators named, e.g. . In this case the php file would be: APPLICATION_PATH/validators/Age.php. With this setup I need to add the validators path to the Zend_Autoloader. For this purpose in the Bootstrap.php I have:

 protected function _initAutoload() {
    $autoLoader = Zend_Loader_Autoloader::getInstance();

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

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

    $autoLoader->pushAutoloader($resourceLoader);

}

Hope this will be of help to you.

Marcin
  • 215,873
  • 14
  • 235
  • 294