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
Php 使用参数定义约束的最佳方法_Php_Symfony_Symfony Validator - Fatal编程技术网

Php 使用参数定义约束的最佳方法

Php 使用参数定义约束的最佳方法,php,symfony,symfony-validator,Php,Symfony,Symfony Validator,我试图在注释中使用参数,但是 e、 g.在对象约束中: ... use Symfony\Component\Validator\Constraints as Assert; class SomeObj { /** * @Assert\File(maxSize="%max_filesize%") */ private $file; ... } in parameters.yml parameters: ... max_files

我试图在注释中使用参数,但是

e、 g.在对象约束中:

...
use Symfony\Component\Validator\Constraints as Assert;

class SomeObj {

    /**
     * @Assert\File(maxSize="%max_filesize%")
     */
    private $file;

    ...

}
in parameters.yml

parameters:
    ...
    max_filesize: 5M
我得到了
ConstraintDefinitionException(“%max\u filesize%”不是有效的最大大小”)


我相信我必须放弃使用注释格式,尝试其他一些(YAML?)。或者使用新类扩展FileConstraint,并通过参数在其中设置$maxFilesize。这个问题的其他解决方案是什么?哪一个是最好的

您应该使用
{{size}
而不是
%max\u filesize%


请参阅。

可能的副本。您能否扩展您的答案?我应该在哪里使用%value%而不是%max\u filesize%,这对我有什么帮助?