stonecolddevin has asked for the wisdom of the Perl Monks concerning the following question:
Howdy all,
I'm having some trouble with DBIx::Class. I'm trying to paginate results, 10 results per page, nothing special.
However, what i'm running into is
I'm honestly baffled, I don't know how this setup is supposed to work, or how to change the paged results, the docs only say:
When you expect a large number of results, you can ask DBIx::Class for a paged resultset, which will fetch only a small number of records at a time:
my $rs = $schema->resultset('Artist')->search(
undef,
{
page => 1, # page to return (defaults to 1)
rows => 10, # number of results per page
},
);return $rs->all(); # all records for page 1
The page attribute does not have to be specified in your search:
my $rs = $schema->resultset('Artist')->search(
undef,
{
rows => 10,
}
);return $rs->page(1); # DBIx::Class::ResultSet containing first 10 records
In either of the above cases, you can return a Data::Page object for the resultset (suitable for use in e.g. a template) using the pager method:
return $rs->pager();
return $rs->page(1); # DBIx::Class::ResultSet containing first 10 records <- this doesn't work either. Currently, I have something like this:
sub main { my $self = shift; my $tmpl = $self->load_tmpl( 'index.html', %config_vars ); my $q = $self->query; my $comments = $schema->resultset('News')->search( undef, { rows => 10, page => $q->param('next_page'), order_by => 'date DESC' } ); ## let's populate @comments for ( $comments->all ) { my %row_data; #$row_data{'comment_id'} = $_->comment_id; $row_data{'post_subject'} = $_->subject; $row_data{'post_author'} = $_->author; $row_data{'post_date'} = $_->date; $row_data{'post_id'} = $_->postid; $row_data{'post_content'} = $_->story; #$row_data{'is_hidden'} = $_->is_hidden; # push it into the the loop.... push ( @end_posts, \%row_data ); } $tmpl->param( site_title => $self->param('main_page_title'), site_css => 'css/main.css', post_data => \@end_posts, next_page => $comments->pager->next_page, previous_page => $comments->pager->previous_page, ); $tmpl->output; }
All I can think of is maybe page => $q->param('next_page'), this attribute is somehow effing things up, but it's creating the necessary two pages...so I really can't say.
I've scoured all the docs and I just can't find anything. Am I missing something monks?
UPDATE:Looks like changing page => $q->param('next_page') to page => $q->param('next_page') || 1 and
tomy $comments = $schema->resultset('News')->search( undef, { rows => 10, page => $q->param('next_page'), order_by => 'date DESC' } );
did the trick...(thanks LTJake :-))my $comments = $schema->resultset('News')->search( {}, { rows => 10, page => $q->param('next_page'), order_by => 'date DESC' } );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBIx::Class Pagination troubles
by castaway (Parson) on Sep 25, 2006 at 16:10 UTC | |
by stonecolddevin (Parson) on Sep 25, 2006 at 17:05 UTC | |
Re: DBIx::Class Pagination troubles
by haoess (Curate) on Sep 26, 2006 at 07:12 UTC | |
Re: DBIx::Class Pagination troubles
by mreece (Friar) on Sep 25, 2006 at 16:32 UTC | |
by stonecolddevin (Parson) on Sep 25, 2006 at 17:03 UTC | |
Re: DBIx::Class Pagination troubles
by fmerges (Chaplain) on Sep 30, 2006 at 00:05 UTC | |
Re: DBIx::Class Pagination troubles
by spatterson (Pilgrim) on Sep 27, 2006 at 10:47 UTC | |
by stonecolddevin (Parson) on Sep 27, 2006 at 15:40 UTC | |
by dreel (Sexton) on Sep 19, 2007 at 06:24 UTC |