【发布时间】:2015-07-13 01:55:36
【问题描述】:
我正在使用 Symfony 2.6,我正在按照这些教程学习如何使用验证回调约束:
http://symfony.com/blog/new-in-symfony-2-4-a-better-callback-constraint
http://symfony.com/doc/current/reference/constraints/Callback.html#external-callbacks-and-closures
为了调用外部验证调用,我尝试使用以下 yaml 配置:
App\APIBundle\Entity\Order:
properties:
id:
- Type:
type: integer
message: "Der Wert {{ value }} ist kein gültiger {{ type }}."
amount:
- Type:
type: integer
message: "Der Wert {{ value }} ist kein gültiger {{ type }}."
groups: [ "AppOrder", "AppOrderbasket" ]
- Callback: [App\APIBundle\Validator\Validator, validate]
groups: [ "AppOrder", "AppOrderbasket" ]
我在尝试使用 external 回调验证类验证 amount 属性时遇到以下问题:
验证类 App\APIBundle\Validator\Validator 中的函数“validate”根本不会被调用。我试图通过将“组”属性添加到回调约束来添加验证组。这似乎无效,因为我收到此警告(警告:trim() 期望参数 1 为字符串,给定数组);
如果我删除“groups”属性,警告消失,但验证器仍未被调用。
有什么想法吗?
提前致谢
宁斯基
【问题讨论】:
标签: validation symfony