douluan5738 2016-06-29 17:50
浏览 32

FormType的验证组 - 问题解决方法

I am refering to a missing feature in Symfony: https://github.com/symfony/symfony/issues/3622

I have several entities that have a OneToOne-relation to an Address entity. All these OneToOne-relations come alongside the constraint @Valid(). Consequently, I have an AddressFormType that is embedded in other forms. Sometimes the addresses in the various forms are required and sometimes they are not.

Problem

Even when I have a validation group defined in the entity Address, it is not possible to pass this validation group along using the following code:

$builder->add('address', AddressFormType::class, array(
    'required' => true,
    'validation_groups' => array('required'),
));

Now, until Symfony 3.0.0 adding a cascade_validation could fix this problem. Unfortunately, cascade_validation was removed in Symfony 3.0.0 and no solution for the problem at hand was provided.

Possible Work-Around

It is possible to disable the validation for the address field all together and simply validate it in the controller. However, due to the fact that I am using the FOSUserBundle combined with the PUGXMultiUserBundle, that would be an enormous work-around for such a little problem.

Question

Are there any alternatives to validate the addresses properly?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度