Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 如何在yaml中对验证组使用symfony回调约束?_Validation_Symfony - Fatal编程技术网

Validation 如何在yaml中对验证组使用symfony回调约束?

Validation 如何在yaml中对验证组使用symfony回调约束?,validation,symfony,Validation,Symfony,我使用的是Symfony 2.6,下面是如何使用验证回调约束的教程: 要调用外部验证调用,我尝试使用以下yaml配置: App\APIBundle\Entity\Order: properties: id: - Type: type: integer message: "Der Wert {{ value }} ist kein gültiger {{ type }}." amount: - Ty

我使用的是Symfony 2.6,下面是如何使用验证回调约束的教程:

要调用外部验证调用,我尝试使用以下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" ]
尝试使用外部回调验证类验证金额属性时,我遇到以下问题:

验证类App\APIBundle\Validator\Validator中的函数“validate”根本不会被调用。我试图通过向回调约束添加“groups”属性来添加验证组。这似乎是无效的,因为我得到了这个警告(警告:trim()希望参数1是字符串,数组给定)

如果我删除了“groups”属性,警告将消失,但仍然没有调用验证程序

有什么想法吗

提前感谢
ninsky

您现在正在将。那不行

如果您只需要指定默认选项(即
回调
约束下的
回调
选项),则可以使用
回调:[App\APIBundle\Validator\Validator,validate]
。但是,如果必须定义两个选项(在您的示例中是
回调
),则必须使用正常语法:

- Callback:
    callback: [App\APIBundle\Validator\Validator, validate]
    groups: [AppOrder, AppOrderbasket]
现在,您将混合使用常规语法。那不行

如果您只需要指定默认选项(即
回调
约束下的
回调
选项),则可以使用
回调:[App\APIBundle\Validator\Validator,validate]
。但是,如果必须定义两个选项(在您的示例中是
回调
),则必须使用正常语法:

- Callback:
    callback: [App\APIBundle\Validator\Validator, validate]
    groups: [AppOrder, AppOrderbasket]