Thanks Lee
Ok - I have stage one working - the click on a header gives the sort
order.
I'll be going onto stage two which will be storing the sort state -
possibly using a "session" variable to do that... ?
Ady
//
--------------------------------------------------------------------------------------------
/* frontend/modules/unit/actions/actions.class.php
* snipped down for simplicity
*/
class unitActions extends sfActions
{
// used to get the sort order for the Unit table
protected function getSortOrder($sortBy) {
$sortCol = UnitPeer::ID;
if ($sortBy=='state') {
$sortCol = UnitPeer::STATE_CODE;
} elseif ($sortBy=='national') {
$sortCol = UnitPeer::NATIONAL_CODE;
} elseif ($sortBy=='name') {
$sortCol = UnitPeer::NAME;
} elseif ($sortBy=='hours') {
$sortCol = UnitPeer::NOMINAL_HOURS;
}
return $sortCol;
}
// generates the default of all records listed in units table
public function executeIndex(sfWebRequest $request)
{
$sortBy='';
if ($request->hasParameter('sortby')) {
$sortBy = $request->getParameter('sortby');
}
$this->sortby = $sortBy;
$c = new Criteria();
$c->addAscendingOrderByColumn($this->getSortOrder($sortBy));
$this->unit_list = UnitPeer::doSelect($c);
}
// generates a paged set of results from the units table
public function executeList(sfWebRequest $request)
{
$sortBy='';
if ($request->hasParameter('sortby')) {
$sortBy = $request->getParameter('sortby');
}
$this->sortby = $sortBy;
$c = new Criteria();
$c->addAscendingOrderByColumn($this->getSortOrder($sortBy));
$pager = new sfPropelPager('Unit', 10);
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter('page', 1));
$pager->init();
$this->unit_list = $pager;
}
}
//
--------------------------------------------------------------------------------------------
/* frontend/modules/unit/templates/_list.php
*/
<table>
<thead>
<tr>
<th> <?php echo link_to( 'State code', 'unit/index?
sortby=state' ) ?></th>
<th> <?php echo link_to( 'National code', 'unit/index?
sortby=national') ?></th>
<th> <?php echo link_to( 'Name', 'unit/index?sortby=name') ?></
th>
<th> <?php echo link_to( 'Nominal Hours', 'unit/index?
sortby=hours') ?></th>
</tr>
</thead>
<tbody>
<?php $i=0;
foreach ($unit_list as $unit): ?>
<tr class="<?php echo ($i=($i==0?1:0)) ? 'even' : 'odd' ?>">
<td><?php echo $unit->getStateCode() ?></td>
<td><?php echo $unit->getNationalCode() ?></td>
<td><a href="<?php echo url_for('unit/show?id='.$unit-
>getId()) ?>"><?php echo $unit->getName() ?></td>
<td><?php echo $unit->getNominalHours() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
//
--------------------------------------------------------------------------------------------
/* frontend/modules/unit/templates/indexSuccess.php
*/
<h1>Unit List</h1>
<?php include_partial('unit/list', array('unit_list' => $unit_list)) ?>
<a href="<?php echo url_for('unit/new') ?>">New</a>
//
--------------------------------------------------------------------------------------------
# frontend/config/routing.yml
unit_sort:
url: /unit/:sortby/
param: { module: unit, action: list }
#catch the use of plural units and modules
units:
url: /units/:sortby/
param: { module: unit, action: list }
modules:
url: /modules/:sortby/
param: { module: unit, action: list }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---