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

Commit83a2304

Browse files
committed
validator : choice constraint : explain how to supply choices from a constant
1 parent239136d commit83a2304

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

‎reference/constraints/Choice.rst‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ constraint.
210210
}
211211
}
212212
213-
If the callback isstored in a different class and is static, for example ``AppBundle\Entity\Genre``,
213+
If the callback isdefined in a different class and is static, for example ``AppBundle\Entity\Genre``,
214214
you can pass the class name and the method as an array.
215215

216216
..configuration-block::
@@ -279,6 +279,34 @@ you can pass the class name and the method as an array.
279279
}
280280
}
281281
282+
Supplying the Choices from an Array Constant
283+
--------------------------------------------
284+
285+
You can also directly provide an array constant to the ``choices`` option in the annotation::
286+
287+
// src/AppBundle/Entity/Author.php
288+
namespace AppBundle\Entity;
289+
290+
class Author
291+
{
292+
const GENRES = ['fiction', 'non-fiction'];
293+
294+
/**
295+
* @Assert\Choice(choices=Author::GENRES)
296+
*/
297+
protected $genre;
298+
}
299+
300+
..warning::
301+
302+
Notice that the constant in the option is used without quotes
303+
304+
..note::
305+
306+
If the constant is stored in a different class, you can pass the fully qualified class name
307+
of the class or import this class by adding it to the "use" list.
308+
309+
282310
Available Options
283311
-----------------
284312

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp