@@ -12,7 +12,7 @@ using an email address that already exists in the system.
12
12
| | - `message `_ |
13
13
| | - `em `_ |
14
14
| | - `repositoryMethod `_ |
15
- | | - `errorPath `_ |
15
+ | | - `errorPath `_ |
16
16
| | - `ignoreNull `_ |
17
17
+----------------+-------------------------------------------------------------------------------------+
18
18
| Class | :class: `Symfony\\ Bridge\\ Doctrine\\ Validator\\ Constraints\\ UniqueEntity ` |
@@ -155,7 +155,7 @@ method should return a countable result.
155
155
errorPath
156
156
~~~~~~~~~
157
157
158
- **type **: ``string `` **default **: `` The name of the first `` `field `_
158
+ **type **: ``string `` **default **: The name of the first `field `_
159
159
160
160
.. versionadded :: 2.1
161
161
The ``errorPath `` option was added in Symfony 2.1.
@@ -180,6 +180,7 @@ Consider this example:
180
180
181
181
.. code-block :: php-annotations
182
182
183
+ // src/Acme/AdministrationBundle/Entity/Service.php
183
184
namespace Acme\AdministrationBundle\Entity;
184
185
185
186
use Doctrine\ORM\Mapping as ORM;
@@ -206,7 +207,51 @@ Consider this example:
206
207
public $port;
207
208
}
208
209
209
- Now, the message would be bound to the form field of the `port ` with this configuration.
210
+ .. code-block :: xml
211
+
212
+ <!-- src/Acme/AdministrationBundle/Resources/config/validation.xml -->
213
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
214
+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
215
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
216
+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
217
+
218
+ <class name =" Acme\AdministrationBundle\Entity\Service" >
219
+ <constraint name =" Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity" >
220
+ <option name =" field" >
221
+ <value >host</value >
222
+ <value >port</value >
223
+ </option >
224
+ <option name =" errorPath" >port</option >
225
+ <option name =" message" >This port is already in use on that host.</option >
226
+ </constraint >
227
+ </class >
228
+
229
+ </constraint-mapping >
230
+
231
+ .. code-block :: php
232
+
233
+ // src/Acme/AdministrationBundle/Entity/Service.php
234
+ namespace Acme\AdministrationBundle\Entity;
235
+
236
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
237
+ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
238
+
239
+ class Service
240
+ {
241
+ public $host;
242
+ public $port;
243
+
244
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
245
+ {
246
+ $metadata->addConstraint(new UniqueEntity(array(
247
+ 'fields' => array('host', 'port'),
248
+ 'errorPath' => 'port',
249
+ 'message' => 'This port is already in use on that host.',
250
+ )));
251
+ }
252
+ }
253
+
254
+ Now, the message would be bound to the form field of the ``port `` with this configuration.
210
255
211
256
212
257
ignoreNull
0 commit comments