@@ -19,6 +19,16 @@ Basic Usage
1919
2020.. configuration-block ::
2121
22+ .. code-block :: yaml
23+
24+ # src/Acme/BlogBundle/Resources/config/validation.yml
25+ Acme\BlogBundle\Entity\Author :
26+ properties :
27+ bioUrl :
28+ - Url : ~
29+ message : The url "{{ value }}" is not a valid url.
30+ protocols : [http, https]
31+
2232 .. code-block :: php-annotations
2333
2434 // src/Acme/BlogBundle/Entity/Author.php
@@ -29,19 +39,14 @@ Basic Usage
2939 class Author
3040 {
3141 /**
32- * @Assert\Url()
42+ * @Assert\Url(
43+ * message = "The url '{{ value }}' is not a valid url",
44+ * protocols = {"http", "https"}
45+ * )
3346 */
3447 protected $bioUrl;
3548 }
3649
37- .. code-block :: yaml
38-
39- # src/Acme/BlogBundle/Resources/config/validation.yml
40- Acme\BlogBundle\Entity\Author :
41- properties :
42- bioUrl :
43- - Url : ~
44-
4550 .. code-block :: xml
4651
4752 <!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
@@ -52,7 +57,13 @@ Basic Usage
5257
5358 <class name =" Acme\BlogBundle\Entity\Author" >
5459 <property name =" bioUrl" >
55- <constraint name =" Url" />
60+ <constraint name =" Url" >
61+ <option name =" message" >The url "{{ value }}" is not a valid url.</option >
62+ <option name =" protocols" >
63+ <value >http</value >
64+ <value >https</value >
65+ </option >
66+ </constraint >
5667 </property >
5768 </class >
5869 </constraint-mapping >
@@ -69,7 +80,10 @@ Basic Usage
6980 {
7081 public static function loadValidatorMetadata(ClassMetadata $metadata)
7182 {
72- $metadata->addPropertyConstraint('bioUrl', new Assert\Url());
83+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
84+ 'message' => 'The url "{{ value }}" is not a valid url.',
85+ 'protocols' => array('http', 'https'),
86+ )));
7387 }
7488 }
7589
0 commit comments