Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions en/core-libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

@cleptric cleptric May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 3.5.0?
EDIT: Was fixed post merge 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry about sneaking that in.


You can use the `Localized plugin <https://github.com/cakephp/localized>`_ to
get providers based on countries. With this plugin, you'll be able to validate
model fields, depending on a country, ie::
Expand Down