Skip to content

Commit b3b5579

Browse files
authored
Update validation.rst
When looking at the docs, it seems that you can only use 1 file (validation.yaml|xml) for your validation config. Symfony looks for all the files in config/validator
1 parent a564d70 commit b3b5579

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

validation.rst

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ application. The goal of validation is to tell you if the data
4444
of an object is valid. For this to work, you'll configure a list of rules
4545
(called :ref:`constraints <validation-constraints>`) that the object must
4646
follow in order to be valid. These rules are usually defined using PHP code or
47-
annotations but they can also be defined as a ``validation.yaml`` or
48-
``validation.xml`` file inside the ``config/validator/`` directory:
47+
annotations but they can also be defined as ``.yaml`` or
48+
``.xml`` files inside the ``config/validator/`` directory:
4949

5050
For example, to guarantee that the ``$name`` property is not empty, add the
5151
following:
@@ -277,6 +277,53 @@ previous configuration by the following:
277277
],
278278
]);
279279
280+
By default, config files are located in the ``config/validator/`` directory.
281+
It is possible to define an array of paths with files or directories where the component will look for additional validation files:
282+
283+
.. configuration-block::
284+
285+
.. code-block:: yaml
286+
287+
# config/packages/framework.yaml
288+
framework:
289+
validation:
290+
mapping:
291+
paths:
292+
- "%kernel.project_dir%/validation/"
293+
294+
.. code-block:: xml
295+
296+
<!-- config/packages/framework.xml -->
297+
<?xml version="1.0" encoding="UTF-8" ?>
298+
<container xmlns="http://symfony.com/schema/dic/services"
299+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
300+
xmlns:framework="http://symfony.com/schema/dic/symfony"
301+
xsi:schemaLocation="http://symfony.com/schema/dic/services
302+
https://symfony.com/schema/dic/services/services-1.0.xsd
303+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
304+
305+
<framework:config>
306+
<framework:validation>
307+
<framework:mapping>
308+
<framework:path>%kernel.project_dir%/validation</framework:path>
309+
</framework:mapping>
310+
</framework:validation>
311+
</framework:config>
312+
</container>
313+
314+
.. code-block:: php
315+
316+
// config/packages/framework.php
317+
$container->loadFromExtension('framework', [
318+
'validation' => [
319+
'mapping' => [
320+
'paths' => [
321+
'%kernel.project_dir%/validation',
322+
],
323+
],
324+
],
325+
]);
326+
280327
.. index::
281328
single: Validation; Constraints
282329

0 commit comments

Comments
 (0)