[Catalyst] Pagenav?

Jonathan Rockway jon at jrock.us
Fri Feb 9 20:02:45 GMT 2007


Bernhard Janetzki wrote:
> Hey Guys,
> i am wondering if there is a pagenavigation-View e.g. (Page 1|2|3...100) available? 

If you're using DBIC, try $resultset->page($page_number) and
$resultset->pager.  The pager (Data::Page) object will give you all the
vital information like current page #, last page #, # of items on the
current page (and lots more).  The ->page method will get page n of the
resultset for you.  The code would look something like this:

controller:

$page = $c->req->param('page') || 1;
$rs = $c->model('DBIC')->search->whatever;
$c->stash(results => [$rs->page($page)]);
$c->stash(pager => $rs->pager);

Template:

Page [% pager.current_page %] of [% pager.last_page %]
(results [% pager.first %] - [% pager.last %] of [% pager.total_entries %]

[% FOREACH row = results %]
[% PROCESS row ... %]
[% END %]

<a href="[% c.req.uri_with({page => pager.next_page}) %]">Next</a>
etc.

Hope this helps.  You might want to use Data::Page::Navigation to help
with the 1 2 3 4 5 ... stuff.

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list