问题描述
我在做应用程序,我在其中使用SQL,我想将复选框值保存在一列中。
i正在这样做:
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');
}
但我收到错误消息,提示我有SELECT错误,我认为问题出在复选框。这样对吗?你能帮我怎么做吗?
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 ?
推荐答案
您可以将列类型更改为数组,如下所示:
You can change the column type to "array" like this:
@ORM\Column(name="ingredients", type="array", nullable=true)
这将导致带有注释(DC2Type:array)的长文本字段,因此Doctrine知道如何处理它。它将存储序列化的数组。
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.
这篇关于使用Symfony 2,Doctrine将数组保存到SQL数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!