0

I have a sfWidgetFormDoctrineChoiceMany widget, I was wondering if there was a way to order the data inside it in ascending order

  'locations_list'  => new sfWidgetFormDoctrineChoiceMany(array('model' => 'Location')),
seus
  • 568
  • 9
  • 31

1 Answers1

2

To set ordering on sfWidgetFormDoctrineChoiceMany (and sfWidgetFormDoctrineChoice too) you should provide a order_by option. Like this:

// ...
'locations_list' => new sfWidgetFormDoctrineChoiceMany(array(
    'model'    => 'Location',
    'order_by' => array('Name', 'asc'), // <--- replace 'Name' with your column name in camel-case format
)),
// ...

When I need to get a quick reference on widget supported options, I always go to it's source. Usually they have a nice documentation right in PHP comments. Check this link to sfWidgetFormDoctrineChoice source:

https://github.com/nationalfield/symfony/blob/a2d4442dfeb26355e89360f6e725c1f19c3a1ee0/lib/plugins/sfDoctrinePlugin/lib/widget/sfWidgetFormDoctrineChoice.class.php#L33

e1v
  • 627
  • 4
  • 7
  • 1
    Worth noting that it also accepts a doctrine query if further filtering is needed. http://symfony.com/legacy/doc/forms/1_4/en/A-Widgets#chapter_a_sub_choice_bound_to_a_doctrine_model – Jestep May 31 '16 at 17:42