[Catalyst] DBIx::Class/TT Pager Question
Hermida, Leandro
Leandro.Hermida at fmi.ch
Fri Dec 29 16:57:27 GMT 2006
> From: Dennis Daupert [mailto:ddaupert at sbcglobal.net]
>
> 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(); # ???
>
> }
Hi, you are setting $c->stash->{photos} to an array reference when you
do $c->stash->{photos} = [$c->model( ... ]; and then you are later
trying to make a method call ->pager() on that array reference, not an
object. This is why you are getting this error.
Another observation is that you don't need to use Data::Page directly in
order to page results using DBIx::Class. Its built in for you. See the
"Paged Results" section of the DBIx::Class::Manual::Cookbook POD on
CPAN.
Leandro
More information about the Catalyst
mailing list