[Catalyst] Relative links
Marcello
m.romani at spinsoft.it
Thu Nov 10 09:33:59 CET 2005
Bill Moseley ha scritto:
> Relative links are biting me again, so I'm wondering how others
> generate links in a sane way.
>
> I have an action /admim/things that displays a table of rows. I have
> some common template code for displaying tables that include column
> headings that can be clicked on for sorting by that column. For those
> headings I use relative links so the template code is portable:
>
> <th><a href="?o=date">Date</a></th>
> <th><a href="?o=name">Name</a></th>
>
> That works great, in general. Plus, it allows any additional
> arguments to be included in the links. (e.g. /admin/things/blue might
> limit to just the blue things, so the sort would be
> /admin/things/blue?o=date).
>
> But that same feature causes trouble when forwarding from another
> action.
>
> An example might be where I re-show the list after deleting an item:
>
> package App::C::Admin::Thing;
>
> sub delete {
> my ($self, $c, $id ) = @_;
> DB::Thing->retrieve($id)->delete;
> $c->stash->{message} = "Thingy $id was deleted";
> $c->forward('/admin/things'); # App::C::Admin::things() : Local
> }
>
> Then the relative links on the table end up like this, of course:
>
> /admin/thing/delete/234?o=date
>
> instead of:
>
> /admin/things?o=date
>
> I can't use $c->req->action or $c->req->match as that's the action
> that matched the original request (/admin/thing/delete/234). I
> suppose I could redirect, but that's very ugly.
But if you don't redirect the user will see /admin/thing/delete/234
while the page displays a listing of things.
If she presses the reload button after deleting something, the action
that gets replayed is not the listing but the deletion, probably
bringing her to an error page because the item with the displayed id
doesn't exist anymore (it's just been deleted).
This is my experience and why I redirect after a deletion.
But I agree that redirecting is quite ugly (not to mention slooow).
>
> I originally was creating a $c->stash->{myself} entry for
> self-referencing links in all my controllers. Seems like the only way
> since Catalyst can't really know what action is the "self".
>
> I guess it's more than relative links. If I create links using
> $c->req->action forwarding screws that up, too.
>
>
--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it
More information about the Catalyst
mailing list