8000 [#4233][#4094] Making validateValue and validate changes · symfony/symfony-docs@9874d8e · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9874d8e

Browse files
committed
[#4233][#4094] Making validateValue and validate changes
1 parent 94fc520 commit 9874d8e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

book/validation.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,13 @@ With this configuration, there are three validation groups:
822822
fields only.
823823

824824
To tell the validator to use a specific group, pass one or more group names
825-
as the second argument to the ``validate()`` method::
825+
as the third argument to the ``validate()`` method::
826826

827-
$errors = $validator->validate($author, array('registration'));
827+
// If you're using the new 2.5 validation API (you probably are!)
828+
$errors = $validator->validate($author, null, array('registration'));
829+
830+
// If you're using the old 2.4 validation API
831+
// $errors = $validator->validate($author, array('registration'));
828832

829833
If no groups are specified, all constraints that belong in group ``Default``
830834
will be applied.
@@ -1189,10 +1193,19 @@ it looks like this::
11891193
$emailConstraint->message = 'Invalid email address';
11901194

11911195
// use the validator to validate the value
1196+
// If you're using the new 2.5 validation API (you probably are!)
1197+
$errorList = $this->get('validator')->validate(
1198+
$email,
1199+
$emailConstraint
1200+
);
1201+
1202+
// If you're using the old 2.4 validation API
1203+
/*
11921204
$errorList = $this->get('validator')->validateValue(
11931205
$email,
11941206
$emailConstraint
11951207
);
1208+
*/
11961209

11971210
if (count($errorList) == 0) {
11981211
// this IS a valid email address, do something
@@ -1206,13 +1219,13 @@ it looks like this::
12061219
// ...
12071220
}
12081221

1209-
By calling ``validateValue`` on the validator, you can pass in a raw value and
1222+
By calling ``validate`` on the validator, you can pass in a raw value and
12101223
the constraint object that you want to validate that value against. A full
12111224
list of the available constraints - as well as the full class name for each
12121225
constraint - is available in the :doc:`constraints reference </reference/constraints>`
12131226
section .
12141227

1215-
The ``validateValue`` method returns a :class:`Symfony\\Component\\Validator\\ConstraintViolationList`
1228+
The ``validate`` method returns a :class:`Symfony\\Component\\Validator\\ConstraintViolationList`
12161229
object, which acts just like an array of errors. Each error in the collection
12171230
is a :class:`Symfony\\Component\\Validator\\ConstraintViolation` object,
12181231
which holds the error message on its ``getMessage`` method.

0 commit comments

Comments
 (0)
0