http://www.symfony-project.org/forum/index.php/m/32611/
One of my most important problem is the reorder of the select menus generated with the foreign values.
Order are done by id and I can't find how to change that.
In order to order the dropdown list, ie, the foreign look up table, you need to define a custom sort order using the peer_method. Here is an example.
Here, the foreign table is staff and foreign key is staff_id.
In the generator.yml on the main admin generator form:
edit:
fields:
staff_id: { params: peer_method=getSortedByName }In lib/model/StaffPeer.php:
class StaffPeer extends BaseStaffPeer
{
// return staff list in the order of First name, Last name
public static function getSortedByName() {
$c = new Criteria();
$c->addAscendingOrderByColumn(StaffPeer::FIRST_NAME);
$c->addAscendingOrderByColumn(StaffPeer::LAST_NAME);
return StaffPeer::doSelect($c);
}
. . .Fields definitions can be found in 'lib/model/om/BaseStaffPeer.php'.
xpt
documented on: 2007.09.20
> do i have the opportunity to list my items in the select tag of my edit form > by name ?
I think it might be possible to define a custom sort order using the peer_method.
documented on: 13 February 2007, mikenolan
Am I right in thinking that Aston wants to sort the order of your select tag?
Here's a quick example I just applied to my 'Page' class and admin generator. It has a parent_id which is a foreign key to itself.
In the generator.yml:
generator:
class: sfPropelAdminGenerator
param:
model_class: Page
theme: default
edit:
fields:
parent_id:
params:
include_blank: true
peer_method: getSortedThen in the PagePeer class I added:
public static function getSorted() {
$c = new Criteria();
$c->addAscendingOrderByColumn(PagePeer::TITLE);
return PagePeer::doSelect($c);
}Clear the cache and reload and your select tag should be sorted alphabetically!
documented on: 15 February 2007, mikenolan