[Catalyst] Help with paging
Dermot
paikkos at googlemail.com
Wed Jul 16 12:54:29 BST 2008
2008/7/16 Octavian Rasnita <orasnita at gmail.com>:
> From: "Dermot" <paikkos at googlemail.com>
>> # Arg where is pager?
>
> Try using:
>
> sub list : Local {
> my ($self, $c) = @_;
>
> my $items = $c->model('MyDB::Items')->search({},{
> page => $page,
> rows => 20,
> });
Where does $page come from? Should I pick that up from @_?
> $c->stash->{pager} = $items->pager;
> $c->stash->{items} = [$items->all];
> $c->stash->{template} = 'items/list.tt2';
>
> Octavian
I am getting an error:
DBIx::Class::ResultSet::pager(): Can't create pager for non-paged rs
Now I see where the paging and DBIx come together.
(DBIx/Class/ResultSet.pm#pager)
$page has to be defined to make the DBIx search work with page/pager.
A bit of trial and error with @_ and $c->request->param and I stumbled onto this
my ($self, $c) = @_;
$c->log->debug("Page=",$c->request->param('page'));
my $page = $c->request->param('page');
$page = 1 if ($page !~ /^\d+$/);
And it all works like a dream. Amazing. Thanx Octavian.
More information about the Catalyst
mailing list