<meta charset="utf-8"><div>Short version:</div><div><div><br></div><div>Using [% c.req.uri_with({ page =&gt; 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&#39;t had much luck finding answers via googling combinations of &#39;perl catalyst post cache pager&#39; ... so pointers are welcome:</div>
<div><br></div><div><br></div><div># Form has lots of fields, we&#39;ll just nab a sample handful from the POST:</div><div><br></div><div>my @terms = map{s/\s+//; $_} split /,/, $form-&gt;field(&#39;keywords&#39;);</div><div>
# I know, but it&#39;s just an example, this isn&#39;t a robust search-field parser :)</div><div><br></div><div>my %search = (</div><div>    asof =&gt; {</div><div>        # date field &quot;asof&quot; must be within date range</div>
<div>        &#39;&gt;=&#39; =&gt; $form-&gt;field(&#39;start_date&#39;),</div><div>        &#39;&lt;=&#39; =&gt; $form-&gt;field(&#39;end_date&#39;),</div><div>    },</div><div>    terms =&gt; [</div><div>        # field &quot;terms&quot; can contain any of the keywords</div>
<div>        map { +{ -like =&gt; &#39;%&#39; . $_ . &#39;%&#39; } } @terms</div><div>    ],</div><div>);</div><div><br></div><div>my $page = $c-&gt;req-&gt;param(&#39;page&#39;);</div><div>$page = 1 if ! defined( $page ) || ! $page || $page =~ /\D/;</div>
<div>my $result = $c-&gt;model(&#39;Package&#39;)-&gt;search( \%search, {page=&gt;$page} );</div><div><br></div><div>$c-&gt;stash-&gt;{results} = $result;</div><div>$c-&gt;stash-&gt;{pager} = $result-&gt;pager; </div><div>
<br></div><div><br></div><div>Then, in the template:</div><div><br></div><div><br></div><div><div>&lt;a href=&quot;[% c.req.uri_with({page =&gt; pager.prev_page}) %]&quot;&gt;Prev&lt;/a&gt;</div></div><div><div>&lt;a href=&quot;[% c.req.uri_with({page =&gt; pager.next_page}) %]&quot;&gt;Next&lt;/a&gt;</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&#39;s the approach for paging the (cached?) query results from a complex-field POSTed search form?</div>
<div><br></div><div>I&#39;m imagining a two-table DB solution where we cache the found row-id&#39;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&#39;m hoping there&#39;s a better way someone has already conjured up that doesn&#39;t have all the drawbacks of this approach that we haven&#39;t even thought of...</div>
<div><br></div><div>Thanks in advance!</div><div><br></div><div><br>-- <br>will trillich<br>&quot;It&#39;s only by saying &#39;no&#39; that you can concentrate on the things that are really important.&quot; -- Steve Jobs</div>
</div><br>-- <br>will trillich<br>&quot;It&#39;s only by saying &#39;no&#39; that you can concentrate on the things that are really important.&quot; -- Steve Jobs<br>