<meta charset="utf-8"><div>Short version:</div><div><div><br></div><div>Using [% c.req.uri_with({ page => pager.next_page }) %] is fine for a simple 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?</div>
<div><br></div><div><br></div><div>Long version:</div><div><br></div><div>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:</div>
<div><br></div><div><br></div><div># Form has lots of fields, we'll just nab a sample handful from the POST:</div><div><br></div><div>my @terms = map{s/\s+//; $_} split /,/, $form->field('keywords');</div><div>
# I know, but it's just an example, this isn't a robust search-field parser :)</div><div><br></div><div>my %search = (</div><div> asof => {</div><div> # date field "asof" must be within date range</div>
<div> '>=' => $form->field('start_date'),</div><div> '<=' => $form->field('end_date'),</div><div> },</div><div> terms => [</div><div> # field "terms" can contain any of the keywords</div>
<div> map { +{ -like => '%' . $_ . '%' } } @terms</div><div> ],</div><div>);</div><div><br></div><div>my $page = $c->req->param('page');</div><div>$page = 1 if ! defined( $page ) || ! $page || $page =~ /\D/;</div>
<div>my $result = $c->model('Package')->search( \%search, {page=>$page} );</div><div><br></div><div>$c->stash->{results} = $result;</div><div>$c->stash->{pager} = $result->pager; </div><div>
<br></div><div><br></div><div>Then, in the template:</div><div><br></div><div><br></div><div><div><a href="[% c.req.uri_with({page => pager.prev_page}) %]">Prev</a></div></div><div><div><a href="[% c.req.uri_with({page => pager.next_page}) %]">Next</a></div>
</div><div><br></div><div><br></div><div>That works well for simple GET forms where the ?field=val syntax is used in the URI.</div><div><br></div><div>What's the approach for paging the (cached?) query results from a complex-field POSTed search form?</div>
<div><br></div><div>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 <a href="http://cached_search.id">cached_search.id</a> 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...</div>
<div><br></div><div>Thanks in advance!</div><div><br></div><div><br>-- <br>will trillich<br>"It's only by saying 'no' that you can concentrate on the things that are really important." -- Steve Jobs</div>
</div><br>-- <br>will trillich<br>"It's only by saying 'no' that you can concentrate on the things that are really important." -- Steve Jobs<br>