[Catalyst] Paging thru a complex POSTed search -- HOWTO?
will at serensoft.com
will at serensoft.com
Wed Jun 2 17:56:00 GMT 2010
Short version:
Using [% c.req.uri_with({ page =3D> pager.next_page }) %] is fine for a sim=
ple
single-field search (where the form uses GET instead of POST)... but how do
we PAGE through (and/or cache) a multi-field form search that uses POST?
Long version:
This is probably already a posted recipe somewhere, but I haven't had much
luck finding answers via googling combinations of 'perl catalyst post cache
pager' ... so pointers are welcome:
# Form has lots of fields, we'll just nab a sample handful from the POST:
my @terms =3D map{s/\s+//; $_} split /,/, $form->field('keywords');
# I know, but it's just an example, this isn't a robust search-field parser
:)
my %search =3D (
asof =3D> {
# date field "asof" must be within date range
'>=3D' =3D> $form->field('start_date'),
'<=3D' =3D> $form->field('end_date'),
},
terms =3D> [
# field "terms" can contain any of the keywords
map { +{ -like =3D> '%' . $_ . '%' } } @terms
],
);
my $page =3D $c->req->param('page');
$page =3D 1 if ! defined( $page ) || ! $page || $page =3D~ /\D/;
my $result =3D $c->model('Package')->search( \%search, {page=3D>$page} );
$c->stash->{results} =3D $result;
$c->stash->{pager} =3D $result->pager;
Then, in the template:
<a href=3D"[% c.req.uri_with({page =3D> pager.prev_page}) %]">Prev</a>
<a href=3D"[% c.req.uri_with({page =3D> pager.next_page}) %]">Next</a>
That works well for simple GET forms where the ?field=3Dval syntax is used =
in
the URI.
What's the approach for paging the (cached?) query results from a
complex-field POSTed search form?
I'm imagining a two-table DB solution where we cache the found row-id's in
table `cached_search_row` and link that to `cached_search`, then have the
cached_search.id mentioned in the URI. I'm hoping there's a better way
someone has already conjured up that doesn't have all the drawbacks of this
approach that we haven't even thought of...
Thanks in advance!
-- =
will trillich
"It's only by saying 'no' that you can concentrate on the things that are
really important." -- Steve Jobs
-- =
will trillich
"It's only by saying 'no' that you can concentrate on the things that are
really important." -- Steve Jobs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100602/ecc09=
07c/attachment.htm
More information about the Catalyst
mailing list