diff --git a/en/core-libraries/validation.rst b/en/core-libraries/validation.rst index 3aa7cdf017..686007b33e 100644 --- a/en/core-libraries/validation.rst +++ b/en/core-libraries/validation.rst @@ -189,6 +189,24 @@ the ``provider`` key in your rule:: 'provider' => 'table' ]); +If you wish to add a ``provider`` to all ``Validator`` objects this can be done +using ``addDefaultProvider()`` method as follows:: + + use Cake\Validation\Validator; + + // Use an object instance. + Validator::addDefaultProvider('custom', $myObject); + + // Use a class name. Methods must be static. + Validator::addDefaultProvider('custom', 'App\Model\Validation'); + +.. note:: + + DefaultProviders must be added before the ``Validator`` object is created + therefore **config/bootstrap.php** is the best place + +.. versionadded:: 3.4.3 + You can use the `Localized plugin `_ to get providers based on countries. With this plugin, you'll be able to validate model fields, depending on a country, ie::