Symfony 1.4订购一个小部件数据

时间:2016-05-27 01:45:27

标签: symfony1 symfony-1.4 symfony-forms doctrine-1.2

我有一个sfWidgetFormDoctrineChoiceMany小部件,我想知道是否有办法按升序排序其中的数据

  'locations_list'  => new sfWidgetFormDoctrineChoiceMany(array('model' => 'Location')),

1 个答案:

答案 0 :(得分:2)

要在 sfWidgetFormDoctrineChoiceMany (以及 sfWidgetFormDoctrineChoice )上设置排序,您应该提供order_by选项。像这样:

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

当我需要快速参考widget支持的选项时,我总是会找到它的来源。通常他们在PHP评论中有一个很好的文档。检查此链接到sfWidgetFormDoctrineChoice源:

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