Save array in SQL database using Symfony 2, Doctri

2019-06-24 02:27发布

i am doing app, where i use SQL and i want to save checkbox values in one column. i am doing it like this:

 /**
* @Assert\NotBlank(
*           message="please select!")
* @Assert\NotNull(
*           message="please select!")
* @Assert\Range(min=0, max=9)
* @ORM\Column(type="integer")
*/  
protected $ingredients;


public static function getIngredientsOptions(){
return array('cheese','tomatoes','salami','onions','mushroom','bacon','ham','vegetables','peppers','olives');

    }

but i get error which says that i have SELECT error, i think problem is with checkbox. is this correct? can you help me how to this ?

1条回答
不美不萌又怎样
2楼-- · 2019-06-24 02:59

You can change the column type to "array" like this:

@ORM\Column(name="ingredients", type="array", nullable=true)

This will result in a longtext field with comment "(DC2Type:array)" so Doctrine knows how to handle it. It will store a serialized array.

This might be what you want. If not, please post some more code of your setter and controller where the form is used, as well as the error message.

查看更多
登录 后发表回答