File tree 3 files changed +52
-0
lines changed 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ below a certain file size and a valid PDF, add the following:
120
120
// src/Acme/BlogBundle/Entity/Author.php
121
121
namespace Acme\BlogBundle\Entity;
122
122
123
+ // ...
123
124
use Symfony\Component\Validator\Mapping\ClassMetadata;
124
125
use Symfony\Component\Validator\Constraints\File;
125
126
Original file line number Diff line number Diff line change @@ -46,6 +46,37 @@ the following:
46
46
protected $age;
47
47
}
48
48
49
+ .. code-block :: xml
50
+
51
+ <!-- src/Acme/EventBundle/Resources/config/validation.yml -->
52
+ <class name =" Acme\EventBundle\Entity\Participant" >
53
+ <property name =" age" >
54
+ <constraint name =" Min" >
55
+ <option name =" limit" >18</option >
56
+ <option name =" message" >You must be 18 or older to enter</option >
57
+ </constraint >
58
+ </property >
59
+ </class >
60
+
61
+ .. code-block :: php
62
+
63
+ // src/Acme/EventBundle/Entity/Participant.php
64
+ namespace Acme\EventBundle\Entity\Participant;
65
+
66
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
67
+ use Symfony\Component\Validator\Constraints as Assert;
68
+
69
+ class Participant
70
+ {
71
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
72
+ {
73
+ $metadata->addPropertyConstraint('age', new Assert\Min(array(
74
+ 'limit' => '18',
75
+ 'message' => 'You must be 18 or older to enter',
76
+ ));
77
+ }
78
+ }
79
+
49
80
Options
50
81
-------
51
82
Original file line number Diff line number Diff line change @@ -127,6 +127,26 @@ message:
127
127
</property >
128
128
</class >
129
129
130
+ .. code-block :: php
131
+
132
+ // src/Acme/BlogBundle/Entity/Author.php
133
+ namespace Acme\BlogBundle\Entity;
134
+
135
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
136
+ use Symfony\Component\Validator\Constraints as Assert;
137
+
138
+ class Author
139
+ {
140
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
141
+ {
142
+ $metadata->addPropertyConstraint('firstName', new Assert\Regex(array(
143
+ 'pattern' => '/\d/',
144
+ 'match' => false,
145
+ 'message' => 'Your name cannot contain a number',
146
+ )));
147
+ }
148
+ }
149
+
130
150
Options
131
151
-------
132
152
You can’t perform that action at this time.
0 commit comments