[cgiapp] Q: Any guidelines for paging thru db records via CGI params?

Ron Savage ron at savage.net.au
Mon May 26 02:09:23 EDT 2008


Hi Cees

> 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.

Yes, I was wondering if I needed it at all.

> $products = Product::Manager->get_products(
>       query =>
>       [
>          ...
>       ],
>       per_page   => 10,
>       page  => 2,
>     );

Yep, already doing that.

> Then in your prev/next links just include the page number they are on,
> and optionally the number of items per page.

I decided to pre-populate the search fields with the user's previous
input, so now all I have to do is set the page number.

It's the precise mechanism for this I'm undecided about.

I'm just testing the onclick way to fiddle the page number with JS
(previous => -1, next => +1) and submit the form.

(Runs test. Ahhhgggg. The JS function is not being called)

> >> 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

Yes, I'm going to avoid sessions (including cookies) for as long as
possible.

> 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 won't either.

> 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.

Hmmmm.

> 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.

Yes, I always default to HTML::Template.

> I am willing to share if anyone is interested.

I'm using CGI::Application::Dispatch. Does that make your module redundant?

If not, and since I'm working at home most of the time at the moment,
perhaps we could turn it into a CPAN-ready module. Let's see if there is
any interest.

-- 
Ron Savage
ron at savage.net.au
http://savage.net.au/index.html




More information about the cgiapp mailing list