You can use multiple custom validators or pass in arbitrary data to custom validators by specifying the validator name as the key in the rules struct.
This example will look for a UniqueInDBValidator
in WireBox and pass in { table = "table_name", column = "column_name" }
to the validate
method.
Using these advanced techniques you can build reusable validators that accept the data they need in the validationData
struct. You can also include multiple custom validators just by specifying each of them as a key.
If you don't have any custom data to pass to a validator, just pass an empty struct ({}
)
WARNING: You can't do a normal wirebox mapping for YourOwnValidator
in your main application. A validator needs an IValidator
interface from the cbvalidation
module. When wirebox inspects the binder, the cbvalidation
module is not loaded yet, so it will error. This can be solved by defining your custom validators in an own module (depending on cbvalidation
) or by mapping your validator in the afterConfigurationLoad()
method of your binder, e.g in config/wirebox.cfc