mwillbanks / MwCommon

Various components to extend and enhance ZF2.
17 stars 5 forks source link

Apigility integration #9

Open karborator opened 8 years ago

karborator commented 8 years ago

How to attach some of these validators to act as a Zend validator , so zend to be able to pass the $options at the constructor (using apigility)

karborator commented 8 years ago

Solved:

at module.config.php add:

'validators' => array(
        'invokables' => array(
            'Namespane\\Validator' => 'Namespane\\Validator' ,
        ),
    ),

find zf-content-validation , select a Controller you want to set custom validator and take a look at the 'input_filter'. Find the Rest Validator of the controller : Api\V1\Rest\ApiService\Validator ( example), then at 'validators' => array() add ::

 'validators' => array(
                    0 => array(
                        'name' => 'MwCommon\\Validator\\VatIN',
                        'options' => array(
                            'country' => 'country',
                        ),
                    ),
                ),

Zend will pass the options to the validator constructor

      'options' => array(
                            'country' => 'some contry the validator want ',
                        ),