0

Hi I'am new in ZF2 and just wanna to add new walidator for PESEL. I create a ZendValidatePesel.php file in /library/Zend/Validator and copied the content from StringLength.php file. Changing class name of course for ZendValidatePesel. Now, I'am trying to use it like:

                'validators' => array(
                    array(
                        'name' => 'ZendValidatePesel',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 11,
                            'max' => 11,
                        ),
                    ),
                ),

and got error:

Plik:
D:\xampp\htdocs\ZendHospital\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:529
Komunikat:
Zend\Validator\ValidatorPluginManager::get was unable to fetch or create an instance for ZendValidatePesel

Please help me..

1
  • Generally, one wouldn't add custom validators - or any custom code - into the library/Zend/* space. Best to use either a module-specific namespace or a separate library. In either case, there are specific autoloading issues. For the latter case, see stackoverflow.com/a/13934480/131824 Commented Dec 2, 2014 at 15:42

1 Answer 1

0

First of all don't add the validator (or anything else for that matter) into vendor namespaces. Instead put it somewhere within your application code. Don't know how your app is structured, but lets say ./module/YourModule/src/YourModule/Validator/ZendValidatePesel.

Then reference your validator class with a full, qualified name, so following my guess it'd be something like:

'validators' => array(
    array(
        'name' => 'YourModule\Validator\ZendValidatePesel', 
        'options' => array(
            // ...
        ),
),

As far as I know that will directly instantiate the validator for you. Not-so-fun-fact: even if you'd register your validator there under the same name as the fqcn, it won't go through the ValidatorPluginManager -- something that I hope will be, or already is fixed in the framework (if it is somebody let me know, because it'd love to have validators with dependencies at last).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.