Sme*_*ven 1 forms validation symfony
->add('shots','file', array(
'multiple' => true,
**'constraints' => array(
new Constraints\Image(array(
'maxSize' => '10M',
'allowSquare' => false,
'allowPortrait' => false,
'minRatio' => 1.43,
'maxRatio' => 2.4
)),
)**
))
Run Code Online (Sandbox Code Playgroud)
这是具有整合形式验证器的symfony表单的一部分.但我得到一个我不明白的错误:
UnexpectedTypeException: Expected argument of type "string", "array" given
Run Code Online (Sandbox Code Playgroud)
没有标记的部分 everthing确实有效.我检查了表单约束的引用,但我没有得到解决方案......
这就是Symfony\Component\Validator\Constraints\FileValidator抛出这个例外.期望您的表单值可以被转换为字符串,但得到数组...
您应该尝试使用All约束作为File的周围约束,如下所示:
->add('shots','file', array(
'multiple' => true,
'constraints' => array(
new All(array(
'constraints' => array(
new Image(array(
'maxSize' => '10M',
'allowSquare' => false,
'allowPortrait' => false,
'minRatio' => 1.43,
'maxRatio' => 2.4
))
)
))
))
))
Run Code Online (Sandbox Code Playgroud)
请参阅http://symfony.com/fr/doc/current/reference/constraints/All.html
| 归档时间: |
|
| 查看次数: |
1313 次 |
| 最近记录: |