@@ -11,6 +11,10 @@ into a database or passed to a web service.
11
11
Symfony provides a `Validator `_ component to handle this for you. This
12
12
component is based on the `JSR303 Bean Validation specification `_.
13
13
14
+ .. index ::
15
+ pair: Validation; Installation
16
+ pair: Validation; Configuration
17
+
14
18
Installation
15
19
------------
16
20
@@ -21,6 +25,12 @@ install the validator before using it:
21
25
22
26
$ composer require symfony/validator doctrine/annotations
23
27
28
+ .. note ::
29
+
30
+ If your application doesn't use Symfony Flex, you might need to do some
31
+ manual configuration to enable validation. Check out the
32
+ :ref: `Validation configuration reference <reference-validation >`.
33
+
24
34
.. index ::
25
35
single: Validation; The basics
26
36
@@ -220,94 +230,6 @@ Inside the template, you can output the list of errors exactly as needed:
220
230
Each validation error (called a "constraint violation"), is represented by
221
231
a :class: `Symfony\\ Component\\ Validator\\ ConstraintViolation ` object.
222
232
223
- .. index ::
224
- pair: Validation; Configuration
225
-
226
- Configuration
227
- -------------
228
-
229
- Before using the Symfony validator, make sure it's enabled in the main config
230
- file:
231
-
232
- .. configuration-block ::
233
-
234
- .. code-block :: yaml
235
-
236
- # config/packages/framework.yaml
237
- framework :
238
- validation : { enabled: true }
239
-
240
- .. code-block :: xml
241
-
242
- <!-- config/packages/framework.xml -->
243
- <?xml version =" 1.0" encoding =" UTF-8" ?>
244
- <container xmlns =" http://symfony.com/schema/dic/services"
245
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
246
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
247
- xsi : schemaLocation =" http://symfony.com/schema/dic/services
248
- https://symfony.com/schema/dic/services/services-1.0.xsd
249
- http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
250
-
251
- <framework : config >
252
- <framework : validation enabled =" true" />
253
- </framework : config >
254
- </container >
255
-
256
- .. code-block :: php
257
-
258
- // config/packages/framework.php
259
- use Symfony\Config\FrameworkConfig;
260
-
261
- return static function (FrameworkConfig $framework) {
262
- $framework->validation()
263
- ->enabled(true)
264
- ;
265
- };
266
-
267
- Besides, if you plan to use annotations to configure validation, replace the
268
- previous configuration by the following:
269
-
270
- .. configuration-block ::
271
-
272
- .. code-block :: yaml
273
-
274
- # config/packages/framework.yaml
275
- framework :
276
- validation : { enable_annotations: true }
277
-
278
- .. code-block :: xml
279
-
280
- <!-- config/packages/framework.xml -->
281
- <?xml version =" 1.0" encoding =" UTF-8" ?>
282
- <container xmlns =" http://symfony.com/schema/dic/services"
283
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
284
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
285
- xsi : schemaLocation =" http://symfony.com/schema/dic/services
286
- https://symfony.com/schema/dic/services/services-1.0.xsd
287
- http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
288
-
289
- <framework : config >
290
- <framework : validation enable-annotations =" true" />
291
- </framework : config >
292
- </container >
293
-
294
- .. code-block :: php
295
-
296
- // config/packages/framework.php
297
- use Symfony\Config\FrameworkConfig;
298
-
299
- return static function (FrameworkConfig $framework) {
300
- $framework->validation()
301
- ->enableAnnotations(true)
302
- ;
303
- };
304
-
305
- .. tip ::
306
-
307
- When using PHP, YAML, and XML files instead of annotations, Symfony looks
308
- for by default in the ``config/validator/ `` directory, but you can configure
309
- other directories with the :ref: `validation.mapping.paths <reference-validation-mapping >` option.
310
-
311
233
.. index ::
312
234
single: Validation; Constraints
313
235
0 commit comments