Just about every app needs to do paging. Using DBIx::Class, grabbing a Data::Page object from a resultset is as easy as calling $rs->pager. Constructing the next/previous page urls can sometimes been an odd challenge. Enter uri_with.
uri_with lets you add new (or replace existing) key-value pairs in the current request's URL. The following Template Toolkit code shows you how to take a URL (eg. http://example.com/search/?q=foo) and append next and previous page numbers (eg. http://example.com/search/?q=foo&page=2). It assumes that you have a Data::Page object in a stash variable called "pager".
[% IF pager.previous_page %]
<a href="[% c.request.uri_with( page => pager.previous_page ) %]">Previous Page</a>
[% END %]
[% IF pager.next_page %]
<a href="[% c.request.uri_with( page => pager.next_page ) %]">Next Page</a>
[% END %]
uri_with (Score:2)
Re: (Score:1)
The function resides in Catalyst::Request [cpan.org]. Its utility is fairly dependent on the fact that we use a URI object for the request URL.
Here's the relevant snippet:
Re: (Score:2)
Re: (Score:1)
Unless i'm misunderstanding your point, I don't believe that method does what we're looking for. Example: say we have the following URL
...and we're generating the "next page" url. The following test script should show the two different methods:
Re: (Score:2)
Re: (Score:1)
The point is you don’t have to construct a URI object. You just call uri_with and everything except the bits you want to override is already set up for you. Buf if you haven’t used an MVCish web app framework (even an ad-hoc one of your own device), you probably won’t appreciate why that’s so very useful.
Re: (Score:2)
quotes (Score:1)
c.request.uri_with( 'page' => pager.next_pageRe: (Score:1)
Nope -- quotes are not strictly required. So says the examples in the docs [cpan.org], at least :)