Symfony2 forms interpret blank strings as nulls

前端 未结 7 2633
温柔的废话
温柔的废话 2021-02-19 09:12

I have a Symfony2 form with a variety of fields, including one optional text field called recap.

This recap field saves perfectly when there\'s

7条回答
  •  轮回少年
    2021-02-19 09:22

    I have another solution for this issue:

    create dummy class

    class EmptyString {
        public function __toString() {
            return '';
        }
    }
    

    and set

    $builder->add('recap', 'text', [
        'empty_data' => new EmptyString(),
    ]);
    

    When entity will be stored to DB, it will automatically converted to empty string.

提交回复
热议问题