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

Commit956f5fc

Browse files
committed
Added docs for GreaterThan validator
1 parent030d05c commit956f5fc

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

‎reference/constraints.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Validation Constraints Reference
2727
constraints/NotIdenticalTo
2828
constraints/LessThan
2929
constraints/LessThanOrEqual
30+
constraints/GreaterThan
3031

3132
constraints/Date
3233
constraints/DateTime
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
GreaterThan
2+
===========
3+
4+
..versionadded::2.3
5+
This constraint is new in version 2.3.
6+
7+
Validates that a value is greater than another value, defined in the options. To
8+
force that a value is greater than or equal to another value, see
9+
:doc:`/reference/constraints/GreaterThanOrEqual`. To force a value is less
10+
than another value, see:doc:`/reference/constraints/LessThan`.
11+
12+
+----------------+---------------------------------------------------------------------------+
13+
| Applies to|:ref:`property or method<validation-property-target>`|
14+
+----------------+---------------------------------------------------------------------------+
15+
| Options| - `value`_|
16+
|| - `message`_|
17+
+----------------+---------------------------------------------------------------------------+
18+
| Class|:class:`Symfony\\Component\\Validator\\Constraints\\GreaterThan`|
19+
+----------------+---------------------------------------------------------------------------+
20+
| Validator|:class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanValidator`|
21+
+----------------+---------------------------------------------------------------------------+
22+
23+
Basic Usage
24+
-----------
25+
26+
If you want to ensure that the ``age`` of a ``Person`` class is greater than
27+
``18``, you could do the following:
28+
29+
..configuration-block::
30+
31+
..code-block::yaml
32+
33+
# src/SocialBundle/Resources/config/validation.yml
34+
Acme\SocialBundle\Entity\Person:
35+
properties:
36+
age:
37+
-GreaterThan:
38+
value:18
39+
40+
..code-block::php-annotations
41+
42+
// src/Acme/SocialBundle/Entity/Person.php
43+
namespace Acme\SocialBundle\Entity;
44+
45+
use Symfony\Component\Validator\Constraints as Assert;
46+
47+
class Person
48+
{
49+
/**
50+
* @Assert\GreaterThan(
51+
* value = 18
52+
* )
53+
*/
54+
protected $age;
55+
}
56+
57+
..code-block::xml
58+
59+
<!-- src/Acme/SocialBundle/Resources/config/validation.xml-->
60+
<classname="Acme\SocialBundle\Entity\Person">
61+
<propertyname="age">
62+
<constraintname="GreaterThan">
63+
<optionname="value">18</option>
64+
</constraint>
65+
</property>
66+
</class>
67+
68+
..code-block::php
69+
70+
// src/Acme/SocialBundle/Entity/Person.php
71+
namespace Acme\SocialBundle\Entity;
72+
73+
use Symfony\Component\Validator\Mapping\ClassMetadata;
74+
use Symfony\Component\Validator\Constraints as Assert;
75+
76+
class Person
77+
{
78+
public static function loadValidatorMetadata(ClassMetadata $metadata)
79+
{
80+
$metadata->addPropertyConstraint('age', new Assert\GreaterThan(array(
81+
'value' => 18,
82+
)));
83+
}
84+
}
85+
86+
Options
87+
-------
88+
89+
..include::/reference/constraints/_comparison-value-option.rst.inc
90+
91+
message
92+
~~~~~~~
93+
94+
**type**: ``string`` **default**: ``This value should be greater than {{ compared_value }}``
95+
96+
This is the message that will be shown if the value is not equal.

‎reference/constraints/map.rst.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Comparison Constraints
3535
* :doc:`NotIdenticalTo</reference/constraints/NotIdenticalTo>`
3636
* :doc:`LessThan</reference/constraints/LessThan>`
3737
* :doc:`LessThanOrEqual</reference/constraints/LessThanOrEqual>`
38+
* :doc:`GreaterThan</reference/constraints/GreaterThan>`
3839

3940
Date Constraints
4041
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp