[Catalyst] TIP: resolv uri based on delta params
N. Arakawa
n-a at u01.gate01.com
Wed Dec 13 14:04:51 GMT 2006
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); %]">←</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.
--
- N. Arakawa
More information about the Catalyst
mailing list