[Catalyst] TIP: resolv uri based on delta params

Brian Cassidy brian.cassidy at nald.ca
Wed Dec 13 14:18:17 GMT 2006


N. Arakawa wrote:
> I often make a data-table view, which links to similar views with
> small parameter changes, such as paging or sorting order.
>
> In this case, making a link URI based on 'delta' information is handy.
>
> In Application Code:
>   sub uri_delta{
>     my($self, at arg)=@_;
>     if (@arg % 2 != 0){
>       $self->log->error("Odd elements for a hash!");
>       return "Odd elements for a hash!";
>     }else{
>       my %new_param = (%{$self->request->parameters}, @arg);
>    # Which is better, 'parameters' or 'query_parameters' ?
>       return $self->uri_for($self->action,\%new_param);
>     }
>   }
>
> In TT-Template:
>  <a href="[% Catalyst.uri_delta('page', prev); %]">&larr;</a>
>
> There is at least one drawback of this approach:
>  it is not possible to 'delete' a parameter.
> However, assign 'undef' instead of deleting  parameter often enough.
>
>   
Is this any different than $c->req->uri_with()?

-Brian



More information about the Catalyst mailing list