[cgiapp] Q: Any guidelines for paging thru db records via CGI
params?
Cees Hek
ceeshek at gmail.com
Mon May 26 00:40:17 EDT 2008
On Mon, May 26, 2008 at 1:36 PM, Ron Savage <ron at savage.net.au> wrote:
> Hi Dan
>
>> I like Data::Page::Navigation. Each link for selecting a page would
>> include the search criteria including the page number. DBIx::Class offers
>
> I'm intending to use Data::Page.
Hi Ron,
If you are using Rose, then you don't need to bother with Data::Page.
Rose provides convenience methods to do your limit/offset values.
$products = Product::Manager->get_products(
query =>
[
...
],
per_page => 10,
page => 2,
);
Then in your prev/next links just include the page number they are on,
and optionally the number of items per page.
>> a database agnostic syntax for limiting the rows returned to the page
>> requested, so I guess Rose would too.
>
> Yes it does. The question is how to let the end user manage the
> transition from page to page.
If it is a search result that you are displaying, then I usually just
pass the original search parameters along with the page number in the
prev and next links. The benefit of that is that you don't need to
worry about sessions, or storing the search results. The potential
drawback is that the search results could change from page to page if
the data being searched changes rapidly (ie a new product may be added
that matches the search criteria which will bump the search results
around a bit). I don't worry about that too much though.
I wrote a CGI::App plugin that does paging a few years ago, but I
never released it. It manages all the URL generation for you, and all
you have to do is give it the total number of search results. It
gleans the other info (like page number) from the current query
params, so it can properly highlight what page you are on. I use it
with Rose::DB::Object and it makes life very easy.
One drawback you might have on my solution is that it uses
Template::Toolkit, and I believe you are still in the HTML::Template
camp, so it may not be right for you. It could be made to work with
HTML::Template though.
I am willing to share if anyone is interested.
Cheers,
Cees
More information about the cgiapp
mailing list