schema:
----------
state:
id:
name: VARCHAR(255)
agency:
id:
name: VARCHAR(255)
state_id:
The function to sort in actions.class.php
--------------------------------------------
public function executeSort(sfWebRequest $request) {
$field_name = $request->getParameter('column');
$sortby = $request->getParameter('by');
$c= new Criteria();
if($field_name == "state_id") {
$c->addJoin(AgencyPeer::STATE_ID,StatePeer::ID,Criteria::LEFT_JOIN);
if($sortby == "asc") {
$c->addAscendingOrderByColumn(StatePeer::ABBREVIATION);
}else {
$c->addDescendingOrderByColumn(StatePeer::ABBREVIATION);
}
}else {
if($sortby == "asc") {
$c->addAscendingOrderByColumn(constant("AgencyPeer::".strtoupper($field_name)));
}else {
$c->addDescendingOrderByColumn(constant("AgencyPeer::".strtoupper($field_name)));
}
}
$this->agency_list = AgencyPeer::doSelect($c);
$this->setTemplate('index');
}