I would like to create an optgroup in symfony2 like this:
$category_choices = array(
array('Category 1' => array(
'1' => 'Option 1...',
'2' => 'Option 2...',
'3' => 'Option 3...'
)),
array('Category 2' => array(
'4' => 'Option 4...',
'5' => 'Option 5...'
))
);
$builder->add('category_list', 'choice', array(
'label' => 'Category',
'choices' => $category_choices
));
But I want to get the category choices from the database and I need to execute some actions on them and add them to an array. How can I do this in the same form type? (use doctrine in form type)