Categories
symfony

How to populate object_select_tag with your own objects

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.

13 replies on “How to populate object_select_tag with your own objects”

I see you used also additional parameter text_method. Never seen like that, what it’s for?

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.

can I add parameter to the Peer_method like this:
echo object_select_tag($domain, ‘getObjectId’, array (
‘related_class’ => ‘Object’,
‘peer_method’ => ‘getSortedObject(‘+$pays_id+’)’,
‘control_name’ => ‘object_id’,
‘include_blank’ => true,
));

i know that mila’s method will not work. but is there a good way to pass a paramater to a peer method?

I am new in symfony

where is the file path ObjectPeer.class.php

/lib/model/doctrine/generated/[Filename].class.php ???

to write this code.

static public function getSortedObject() {
$c = new Criteria();
$c->addAscendingOrderByColumn(TablePeer::NAME);
$rs = TablePeer::doSelect($c);
return $rs;
}

Leave a Reply

Your email address will not be published. Required fields are marked *