tags:

views:

444

answers:

1

If you create a checkbox list in symfony 1.2 you get an array with the checked options back in the form. If you save the form, your database now contains the words "Array". Is there a way around this? Or should I just json_encode / json_decode the array as ncecessary and save it manually? Seems awfully tedious. Thanks for reading.

A: 

You can use serialize() and unserialize() functions when saving and getting data.

I don't know which orm using but i can explain with propel way.

For example you have post table and Post class. And post table has options column with text or varchar data type.

in Post.class.php your model directory you can define two override methods

setOptions($v)
{
  parent::setOptions(serialize($v));
}

getOptions()
{
  return unserialize($this->options);
}

Just like that.

In your view or action you can get all options with $post->getOptions() and you have an Array that contains all option related to your database record.

metoikos