小编HKa*_*lla的帖子

用常量数组填充 ChoiceType

使用底层实体中定义的常量数组填充 Symfony 表单 choiceType 并添加基于相同常量创建断言的最佳方法是什么。\n选项名称应存储在数据库中。

\n\n

我正在使用 Symfony 2.8,这就是我所做的。它运作良好,但我认为必须有一种更简单的方法来处理所有新的表单功能。

\n\n

谢谢,汉内斯

\n\n

实体

\n\n\n\n
class User implements UserInterface, \\Serializable\n{\n    const OCCUPATION_SCHOOL_HIGHER_DEGREE = \'Sch\xc3\xbclerin/Sch\xc3\xbcler an Gymnasium\';\n    const OCCUPATION_SCHOOL_LOWER_DEGREE = \'Sch\xc3\xbclerin/Sch\xc3\xbcler an Haupt-/Real- und anderen Schulen\';\n    const OCCUPATION_WORK_TRAINING = \'Berufsausbildung\';\n    const OCCUPATION_UNIVERSITY = \'Studium an einer Hochschule\';\n    const OCCUPATION_WORK_FULLTIME = \'Vollzeiterwerbst\xc3\xa4tigkeit\';\n    const OCCUPATION_WORK_PARTTIME = \'Teilzeiterwerbst\xc3\xa4tigkeit\';\n    const OCCUPATION_NATIONAL_SERVICE = \'Wehrdienst/Zivildienst/FSJ/F\xc3\x96J\';\n    const OCCUPATION_UNEMPLOYED = \'keine Besch\xc3\xa4ftigung\';\n    const OCCUPATION_OTHERS = \'sonstiges\';\n\n...\n/**\n     * @ORM\\Column(type="string", length=255, nullable=true)\n     * @Assert\\NotBlank(message = "Pflichtfeld.")\n     * @Assert\\Choice(\n     *      choices = {\n …
Run Code Online (Sandbox Code Playgroud)

symfony-forms symfony

5
推荐指数
1
解决办法
2582
查看次数

标签 统计

symfony ×1

symfony-forms ×1