Sta*_*ser 8 variables validation placeholder symfony
此时我正在使用我的Entity类中的Annotations使用Symfony Validator组件实现验证.
Symfony文档显示您可以使用某些占位符通过消息传递变量,这些消息可以由转换器组件转换.
例如,可以编写以下注释:
/**
* Assert\Length(
* min = 5,
* max = 10,
* minMessage = "Title too short: {{ limit }}",
* maxMessage = "Title too long: {{ limit }}"
*/
protected $title;
Run Code Online (Sandbox Code Playgroud)
这很好用,但我想知道你有哪些占位符?是否可以创建自定义占位符?
我知道{{ value }}占位符存在(并且有效),但它不在Symfony的文档页面上,关于如何使用长度验证.
我想使用占位符标签,{{ key }}或者{{ name }}通过字段的技术名称(在本例中为"title"),所以我可以写我的minMessageasminMessage = "{{ field }} too short: {{ limit }}"
我试图检查Symfony的标准组件,看看这些占位符是如何处理的,但我找不到适合我的变量列表.
请帮我!T_T
如果您查看您发布的LengthValidator的代码作为示例,您可以看到这些"变量"只是在其自己的Validator类中替换的静态字符串.
因此,所有这些都是自定义的,这也可能是没有可用列表的原因.
班级:
https://github.com/symfony/Validator/blob/master/Constraints/LengthValidator.php
相关片段:
if (null !== $constraint->max && $length > $constraint->max) {
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
->setParameter('{{ value }}', $this->formatValue($stringValue))
->setParameter('{{ limit }}', $constraint->max)
->setInvalidValue($value)
->setPlural((int) $constraint->max)
->setCode(Length::TOO_LONG_ERROR)
->addViolation();
return;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2431 次 |
| 最近记录: |