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 object_select_tag later so that not everybody knows about that. This feature’s name is ‘peer_method’ - effectively you create your peer method which returns objects which must appear in your object_select_tag. So here is the code for object_select_tag:
echo object_select_tag($domain, ‘getObjectId’, array (
‘related_class’ => ‘Object’,
‘peer_method’ => ‘getSortedObject’,
‘control_name’ => ‘object_id’,
‘include_blank’ => true,
));
and this must be put in your ObjectPeer.class.php:
static public function getSortedObject() {
$c = new Criteria();
$c->addAscendingOrderByColumn(TablePeer::NAME);
$rs = TablePeer::doSelect($c);
return $rs;
}
Interesting how this can be done in generator without re-writing of edit_form.php template. I suspect this can be done directly in generator.yml but never tried it. If someone has experienced would be good to know.
Thanks in advance.
As simple as this :
fields:
departement_id: { params: text_method =getNomCode peer_method =doSelectOrderByCode }
November 1, 2007
I see you used also additional parameter text_method. Never seen like that, what it’s for?
It’s the function used to display the name in the select object
by default the text_method is __toString()
[…] How to populate object_select_tag with your own objects […]
I am noob in symfony, but i try to learn. my problem right now is that i am population a object_select_tag, but it is always just displaying the id`s of the table in the list. i have also tried to replace the second parameter with another get function, but it still just shows me the id`s in the list… would be happy about some help, thanks.
April 1, 2008
Works great, thanks!
Comments RSS TrackBack Identifier URI
Leave a comment






6 Comments