Symfony2 data transformers, getting exception message

ⅰ亾dé卋堺 提交于 2019-12-02 04:15:36

问题


I've created my own data transformer, as explained in the dedicated cookbook, here is my reverse transformation:

public function reverseTransform($val)
{
    // ...
    // My logic here
    // ...

    // If $val is not valid
    throw new TransformationFailedException(
        'My custom error message'
    );
}

The question is: how do I get the "custom error message" thrown? I would like to display it as the error message of my form field. How do I do that?

Thanks!


回答1:


Sort answer is: You don't. The transformers job is to, well, transform and not to do error checking.

Add a constraint to the field which will check the transformed value and take care of error messaging.



来源:https://stackoverflow.com/questions/9378863/symfony2-data-transformers-getting-exception-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!