Symfony2 forms interpret blank strings as nulls

前端 未结 7 2281
温柔的废话
温柔的废话 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:39

    Go to your Entity and go to the declaration of the variables.

    /**
     * @var string $name
     *
     * @ORM\Column(type="string", length=50)
     */
    public $recap = '';
    

    you can assign a default value for $recap.

    Or otherway when you have the function setRecap you can check if empty or not set and set the value you expect.

    public function setRecap($recap) {
       $this->recap = !isset($recap) ? '': $recap;
    }
    

    Or you set the default Value in your form Type to '' but i think then its not what you expect.

提交回复
热议问题