I have a Zend Framework application structure as below:
/application
/library
/Zend
/Core
/Filter
/MyFilter.php
/Validator
/MyValidator.php
I would like to put custom filters and validators in their respective folders and have them loaded automatically when used. However, I cannot figure out how to best accomplish this.
I need the solution to work with Zend_Filter_Input in this fashion:
$filters = array(
'month' => 'Digits',
'account' => 'StringTrim',
'other' => 'MyFilter'
);
$validators = array(
'account' => 'Alpha',
'other' => 'MyValidator'
);
$inputFilter = new Zend_Filter_Input($filters, $validators);
What I already know:
I designed and implemented Zend_Filter_Input
back in 2007.
You can add new class prefixes to help load your custom filter and validator classes. By default, Zend_Filter_Input
searches for classes that have the prefixes "Zend_Filter"
and "Zend_Validate"
. Try this:
$inputFilter->addNamespace('Core_Filter');
Before you run isValid()
or other methods of the object.
Alternatively, you can also pass a new class prefix string in the options array, the fourth argument to the Zend_Filter_Input
constructor:
$options = array('inputNamespace' => 'Core_Filter');
$inputFilter = new Zend_Filter_Input($filters, $validators, $data, $options);
See also the documentation I wrote for Zend_Filter_Input
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With