5

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
  • exercise from FH Hagenberg? Commented Nov 27, 2016 at 22:10

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

4 Comments

i changed it but i have error---->> An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.address AS address_3, t0.phone AS phone_4, t0.email AS email_5, t0.box AS box_6, t0.ingredients AS ingredients_7, t0.delivery AS delivery_8 FROM order t0': SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order t0' at line 1
Order is a reserved keyword in SQL, so if you want a table named 'order', you need to escape it: /** @Column(name="order", type=...
You saved me lot of time. Thank you and +1 for you.
I have created an array type field, as you show it. Now I want to look into him. I want to search for an id like 3492 in the array {i: 0; s: 4: "3410"; i: 1; s: 4: "3415"; i: 2; s: 4: "3459"; i: 3; s: 4: "3460"; i: 4; s: 4: "3492";}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.