Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Sign up
Appearance settings

Commit7a3d2a4

Browse files
committed
Merge branch '2.2' into 2.3
2 parents08056fd +1935975 commit7a3d2a4

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

‎cookbook/bundles/inheritance.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ original method, and change its functionality::
7373
the controller using the standard ``FOSUserBundle:Registration:register``
7474
syntax in routes and templates. This is the best practice.
7575

76-
Overriding Resources: Templates, Routing,Validation,etc
77-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
Overriding Resources: Templates, Routing, etc
77+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7878

7979
Most resources can also be overridden, simply by creating a file in the same
8080
location as your parent bundle.
@@ -86,7 +86,7 @@ you can create your own file in the same location of ``AcmeUserBundle``.
8686
Symfony will ignore the file that lives inside the ``FOSUserBundle`` entirely,
8787
and use your file instead.
8888

89-
The same goes for routing files, validation configurationand other resources.
89+
The same goes for routing filesand some other resources.
9090

9191
..note::
9292

@@ -97,8 +97,9 @@ The same goes for routing files, validation configuration and other resources.
9797

9898
..caution::
9999

100-
Translation files do not work in the same way as described above. Read
101-
:ref:`override-translations` if you want to learn how to override
102-
translations.
100+
Translation and validation files do not work in the same way as described
101+
above. Read ":ref:`override-translations`" if you want to learn how to
102+
override translations and see ":ref:`override-validation`" for tricks to
103+
override the validation.
103104

104105
.. _`FOSUserBundle`:https://github.com/friendsofsymfony/fosuserbundle

‎cookbook/bundles/override.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,58 @@ rather than::
117117

118118
$builder->add('name', new CustomType());
119119

120+
.. _override-validation:
121+
120122
Validation metadata
121123
-------------------
122124

123-
In progress...
125+
Symfony loads all validation configuration files from every bundle and
126+
combines them into one validation metadata tree. This means you are able to
127+
add new constraints to a property, but you cannot override them.
128+
129+
To override this, the 3rd party bundle needs to have configuration for
130+
:ref:`validation groups<book-validation-validation-groups>`. For instance,
131+
the FOSUserBundle has this configuration. To create your own validation, add
132+
the constraints to a new validation group:
133+
134+
..configuration-block::
135+
136+
..code-block::yaml
137+
138+
# src/Acme/UserBundle/Resources/config/validation.yml
139+
Fos\UserBundle\Model\User:
140+
properties:
141+
plainPassword:
142+
-NotBlank:
143+
groups:[AcmeValidation]
144+
-Length:
145+
min:6
146+
minMessage:fos_user.password.short
147+
groups:[AcmeValidation]
148+
149+
..code-block::xml
150+
151+
<!-- src/Acme/UserBundle/Resources/config/validation.xml-->
152+
<?xml version="1.0" encoding="UTF-8" ?>
153+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
154+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
155+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
156+
157+
<classname="Fos\UserBundle\Model\User">
158+
<propertyname="password">
159+
<constraintname="Length">
160+
<optionname="min">6</option>
161+
<optionname="minMessage">fos_user.password.short</option>
162+
<optionname="groups">
163+
<value>AcmeValidation</value>
164+
</option>
165+
</constraint>
166+
</property>
167+
</class>
168+
</constraint-mapping>
169+
170+
Now, update the FosUserBundle configuration, so it uses your validation groups
171+
instead of the original ones.
124172

125173
.. _override-translations:
126174

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp