Posted By

ggb2g on 11/02/07


form symfony

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


populate object_select_tag with your own objects in symfony

 / Published in: PHP


Sometimes you need to have an ability to show limited number of elements in your select objects or sort elements by name or so. I figured out that this feature was added to objectselecttag later so that not everybody knows about that. This feature’s name is ‘peermethod’ - effectively you create your peer method which returns objects which must appear in your objectselecttag. So here is the code for objectselect_tag:

  1. echo object_select_tag($domain, ‘getObjectId’, array (
  2. ‘related_class’ => ‘Object’,
  3. ‘peer_method’ => ‘getSortedObject’,
  4. ‘control_name’ => ‘object_id’,
  5. ‘include_blank’ => true,
  6. ));
  8. in your ObjectPeer.php:
  10. static public function getSortedObject() {
  11. $c = new Criteria();
  12. $c->addAscendingOrderByColumn(TablePeer::NAME);
  13. $rs = TablePeer::doSelect($c);
  14. return $rs;
  15. }
  17. and in your yml generator:
  18. fields:
  19. departement_id: { params: text_method =getNomCode peer_method =doSelectOrderByCode }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: shamsh on November 21, 2008

That's a fine example though i found this feature somehow. But if i want to load grouped options then how can i do it with admin generator.

You need to login to post a comment.