[Catalyst] Help with paging

Dermot paikkos at googlemail.com
Wed Jul 16 11:26:09 BST 2008


I'm having issues with paging and could handle some help. I tried
using the examples in the book but it does quite fit what I'm doing. I
have a list method like this:

sub list : Local {
   my ($self, $c) = @_;

   $c->stash->{items} = [$c->model('MyDB::Items')->all];
   $c->stash->{template} = 'items/list.tt2';

# Arg where is pager?
   $c->log->debug("Pager=",$c->request->{'pager'} );
   my $page;
   if ( $c->request->param('page') ) {
           $page = 1 if ($page !~ /^\d+$/);
   else {
        $page = Data::Page->new();
        $page->total_entries(scalar( @{$c->stash->{items}}) );
   $c->stash->{pager} = $page;

And my template has

&lt;&lt;<a href="[% Catalyst.uri_for('list', {page =>
pager.first_page}) %]">First</a>
<a href="[% Catalyst.uri_for('list', {page => pager.previous_page})

All of which works fine on the first page and returns correct urls like

The problems happen when paging through results. Once you start to
nagivate I lose the original Pager object and all it's references.

Can anyone offer a tip here on how to maintain the page/pager object?

Also from my reading of the book it suggests that I don't have worry
about looping through my results (page->entries_per_page) as "Catalyst
and DBIx::Class will handle all the tedious details of paging results


More information about the Catalyst mailing list