@@ -11,6 +11,10 @@ into a database or passed to a web service.
1111Symfony provides a `Validator `_ component to handle this for you. This
1212component is based on the `JSR303 Bean Validation specification `_.
1313
14+ .. index ::
15+ pair: Validation; Installation
16+ pair: Validation; Configuration
17+
1418Installation
1519------------
1620
@@ -21,6 +25,12 @@ install the validator before using it:
2125
2226 $ composer require symfony/validator doctrine/annotations
2327
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+
2434.. index ::
2535 single: Validation; The basics
2636
@@ -220,90 +230,6 @@ Inside the template, you can output the list of errors exactly as needed:
220230 Each validation error (called a "constraint violation"), is represented by
221231 a :class: `Symfony\\ Component\\ Validator\\ ConstraintViolation ` object.
222232
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- $container->loadFromExtension('framework', [
260- 'validation' => [
261- 'enabled' => true,
262- ],
263- ]);
264-
265- Besides, if you plan to use annotations to configure validation, replace the
266- previous configuration by the following:
267-
268- .. configuration-block ::
269-
270- .. code-block :: yaml
271-
272- # config/packages/framework.yaml
273- framework :
274- validation : { enable_annotations: true }
275-
276- .. code-block :: xml
277-
278- <!-- config/packages/framework.xml -->
279- <?xml version =" 1.0" encoding =" UTF-8" ?>
280- <container xmlns =" http://symfony.com/schema/dic/services"
281- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
282- xmlns : framework =" http://symfony.com/schema/dic/symfony"
283- xsi : schemaLocation =" http://symfony.com/schema/dic/services
284- https://symfony.com/schema/dic/services/services-1.0.xsd
285- http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
286-
287- <framework : config >
288- <framework : validation enable-annotations =" true" />
289- </framework : config >
290- </container >
291-
292- .. code-block :: php
293-
294- // config/packages/framework.php
295- $container->loadFromExtension('framework', [
296- 'validation' => [
297- 'enable_annotations' => true,
298- ],
299- ]);
300-
301- .. tip ::
302-
303- When using PHP, YAML, and XML files instead of annotations, Symfony looks
304- for by default in the ``config/validator/ `` directory, but you can configure
305- other directories with the :ref: `validation.mapping.paths <reference-validation-mapping >` option.
306-
307233.. index ::
308234 single: Validation; Constraints
309235
0 commit comments