[Catalyst] DBIx::Class/TT Pager Question
Dennis Daupert
ddaupert at sbcglobal.net
Fri Dec 29 16:35:34 GMT 2006
I'm having a bit of a go of getting all the bits in place to do paging. The error I'm hung on is:
"Can't call method "pager" on unblessed reference"
Here's the story:
My display template first asks the user to select a gallery to display, then displays a list of thumbnail images. My controller 1) runs query to get the galleries for the display template; 2) writes an HTML::Widget form; 3) checks to see if there is a $selected_gallery; 4) If there is, query db for photos.
Line below marked # ??? gives the error; removing that line, I can select a gallery and display the images -- but without paging.
# - - - - - - - - - - - - - - - - - -
package Catapult::Controller::Photo::Gallery;
# - - - - - - - - - - - - - - - - - -
use Data::Page;
################
sub display : Local {
my ($self, $c) = @_;
$c->log->debug("Get Galleries ");
my @galObjs = $c->model("CatapultDB::Galleries")->all();
my @gals = map {$_->id => $_->name }
sort {$a->name cmp $b->name} @galObjs;
my $selected_gallery = $c->request->params->{select_gal};
<snip>
make the html::widget form here
<snip>
if ( $selected_gallery ) {
my $pager = Data::Page->new();
$c->log->debug("Selected Gallery: $selected_gallery");
$c->stash->{photos} = [$c->model('CatapultDB::Photos')->search(
{
'gallery.id' => $selected_gallery
},
{
join => [qw/ gallery /],
prefetch => [qw/ gallery /],
rows => 1,
}
)];
$c->stash->{pager} => $c->stash->{photos}->pager(); # ???
}
# - - - - - - - - - - - - - - - - - -
display.tt
# - - - - - - - - - - - - - - - - - -
[% IF photos.size %]
<h3>Gallery: [% photos.gallery.name %]</h3>
<div id="thumbnails">
<ul>
[% FOREACH photo IN photos -%]
<li>
<a href="[% c.stash.action %]/[% photo.gallery.id %]/[% photo.id %]"
title="[% photo.name %]">
<img src="/static/galleries/[% photo.gallery.directory %]/_t/t_[% photo.filename %]"
alt="[% photo.gallery.name %][% photo.gallery.name %]"></a>
</li>
[% END -%]
</ul>
</div>
[% IF pager.previous_page %]
<a href="[% c.request.uri_with( page => pager.previous_page ) %]">Previous Page</a>
[% END %]
[% IF pager.next_page %]
<a href="[% c.request.uri_with( page => pager.next_page ) %]">Next Page</a>
[% END %]
[% ELSE %]
<h3>There are currently no photos in this gallery.</h3>
[% END %]
# - - - - - - - - - - - - - - - - - -
Help is much appreciated.
/dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061229/f24b96e7/attachment.htm
More information about the Catalyst
mailing list