From 4e446d686cb589835bd84af6ac447f29d9631c86 Mon Sep 17 00:00:00 2001 From: lilHermit Date: Wed, 8 Mar 2017 15:14:55 +0000 Subject: [PATCH 1/2] Documentation update for https://github.com/cakephp/cakephp/pull/10358 --- en/core-libraries/validation.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/en/core-libraries/validation.rst b/en/core-libraries/validation.rst index 3aa7cdf017..97a844ffd5 100644 --- a/en/core-libraries/validation.rst +++ b/en/core-libraries/validation.rst @@ -189,6 +189,23 @@ 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 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** or :php:meth:`~Cake\\ORM\\Table::buildValidator()` + callback 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:: From e0a7818b4ee254e63212eaad3fe8903b0a405a31 Mon Sep 17 00:00:00 2001 From: lilHermit Date: Wed, 8 Mar 2017 15:29:59 +0000 Subject: [PATCH 2/2] Added 'use' statement Revised note --- en/core-libraries/validation.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/en/core-libraries/validation.rst b/en/core-libraries/validation.rst index 97a844ffd5..686007b33e 100644 --- a/en/core-libraries/validation.rst +++ b/en/core-libraries/validation.rst @@ -192,6 +192,8 @@ the ``provider`` key in your rule:: 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); @@ -201,8 +203,7 @@ using ``addDefaultProvider()`` method as follows:: .. note:: DefaultProviders must be added before the ``Validator`` object is created - therefore **config/bootstrap.php** or :php:meth:`~Cake\\ORM\\Table::buildValidator()` - callback is the best place + therefore **config/bootstrap.php** is the best place .. versionadded:: 3.4.3