Skip to content

Instantly share code, notes, and snippets.

@benmanns
Created August 31, 2010 23:46
Show Gist options
  • Save benmanns/559987 to your computer and use it in GitHub Desktop.
Save benmanns/559987 to your computer and use it in GitHub Desktop.
<?php
class GroupsController extends AppController {
var $name = 'Groups';
var $paginate = array(
'fields' => array(
'Group.id',
'Group.icon',
'Group.name',
'GroupCategory.name',
'Group.location',
'Group.description',
'Group.website',
'Group.created',
'SUM(Donation.amount) AS donations',
),
'joins' => array(
array(
'table' => 'donations',
'alias' => 'Donation',
'type' => 'LEFT',
'conditions' => array('Donation.group_id = Group.id'),
),
),
'limit' => 8,
'order' => array(
'Group.name' => 'asc'
),
'group' => 'Group.id',
);
function admin_index() {
if(!empty($this->data)) {
$this->paginate['conditions'] = array(
'MATCH (Group.name, Group.description) AGAINST (? IN BOOLEAN MODE)' => array($this->data['Group']['q'])
);
}
$groups = $this->paginate('Group');
$this->set(compact('groups'));
}
}
?>
@benmanns
Copy link
Author

Please help! I am trying to have the donations column sortable, but visiting the url http://localhost/admin/groups/index/page:1/sort:donations/direction:asc does nothing. If I change the $paginate array to:

'order' => array(
    'donations' => 'desc'
),

the sort works, but after clicking on the sort tab (resulting in the url above) everything breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment