* Catalyst ページング [#a7d2ebbe]
アクションクラスでresultsetクラスをstashに入れて、テンプレートでpagerとallで取り出す。
** アクションクラス [#e58c6a76]
sub list : Local {
my ( $self, $c ) = @_;
my $page = int($c->req->param('page') || 1);
$c->stash->{inquiry} =
$c->model('Myapp::Inquiry')->search({},{page => $page, rows => 10});
$c->stash->{template} = 'inquiry/list.tt2';
}
** テンプレート [#p864ec12]
<div class="pager">
<a href="/inquiry/list?page=[% inquiry.pager.first_page %]"><<</a>
<a href="/inquiry/list?page=[% inquiry.pager.previous_page %]"><</a>
|
<a href="/inquiry/list?page=[% inquiry.pager.next_page %]">></a>
<a href="/inquiry/list?page=[% inquiry.pager.last_page %]">>></a>
[ [% inquiry.pager.current_page %] / [% inquiry.pager.last_page %] ]
</div>
<hr>
<ul>
[% FOREACH inq IN inquiry.all -%]
<li><a href="/inquiry/detail?inquiry_id=[% inq.inquiry_id %]">[% inq.inquiry_id %]</a></li>
[% END -%]
</ul>
** 参考 [#mfe41f43]
- http://search.cpan.org/~jrobinson/DBIx-Class-0.07005/lib/DBIx/Class/ResultSet.pm
- http://search.cpan.org/~blblack/Catalyst-Model-DBIC-Schema-0.18/lib/Catalyst/Model/DBIC/Schema.pm
- http://search.cpan.org/~lbrocard/Data-Page-2.00/lib/Data/Page.pm