@@ -53,21 +53,25 @@ blank but is no longer than 100 characters in length, you would do the following
53
53
54
54
.. code-block :: yaml
55
55
56
- properties :
57
- profileData :
58
- - Collection :
59
- fields :
60
- personal_email : Email
61
- short_bio :
62
- - NotBlank
63
- - MaxLength :
64
- limit : 100
65
- message : Your short bio is too long!
66
- allowMissingFields : true
56
+ # src/BlogBundle/Resources/config/validation.yml
57
+ Acme\BlogBundle\Entity\Author :
58
+ properties :
59
+ profileData :
60
+ - Collection :
61
+ fields :
62
+ personal_email : Email
63
+ short_bio :
64
+ - NotBlank
65
+ - MaxLength :
66
+ limit : 100
67
+ message : Your short bio is too long!
68
+ allowMissingFields : true
67
69
68
70
.. code-block :: php-annotations
69
71
70
72
// src/Acme/BlogBundle/Entity/Author.php
73
+ namespace Acme\BlogBundle\Entity;
74
+
71
75
use Symfony\Component\Validator\Constraints as Assert;
72
76
73
77
class Author
@@ -119,21 +123,21 @@ blank but is no longer than 100 characters in length, you would do the following
119
123
.. code-block :: php
120
124
121
125
// src/Acme/BlogBundle/Entity/Author.php
126
+ namespace Acme\BlogBundle\Entity;
127
+
122
128
use Symfony\Component\Validator\Mapping\ClassMetadata;
123
- use Symfony\Component\Validator\Constraints\Collection;
124
- use Symfony\Component\Validator\Constraints\Email;
125
- use Symfony\Component\Validator\Constraints\MaxLength;
129
+ use Symfony\Component\Validator\Constraints as Assert;
126
130
127
131
class Author
128
132
{
129
133
private $options = array();
130
134
131
135
public static function loadValidatorMetadata(ClassMetadata $metadata)
132
136
{
133
- $metadata->addPropertyConstraint('profileData', new Collection(array(
137
+ $metadata->addPropertyConstraint('profileData', new Assert\ Collection(array(
134
138
'fields' => array(
135
- 'personal_email' => new Email(),
136
- 'lastName' => array(new NotBlank(), new MaxLength(100)),
139
+ 'personal_email' => new Assert\ Email(),
140
+ 'lastName' => array(new Assert\ NotBlank(), new Assert\ MaxLength(100)),
137
141
),
138
142
'allowMissingFields' => true,
139
143
)));
0 commit comments