[Catalyst] Can't seem to use forward or detach. Any special requirements?

J. Shirley jshirley at gmail.com
Mon Apr 27 01:23:03 GMT 2009


On Mon, Apr 27, 2009 at 10:09 AM, <kakimoto at tpg.com.au> wrote:

> Hello, Oliver,
>
>  Good morning.
>  Referring to
>
> http://kobesearch.cpan.org/htdocs/Catalyst-Runtime/Catalyst.html#c_gt_det=
ach_class_method_arguments
> ,
> under "$c->detach()",
> it says that detach is the same as forward, but doesn't return to the
> previous action when processing is finished.
>
>  Comments?
>
> thank you
>
> k. akimoto
>
>
>
> Quoting oliver.g.charles at googlemail.com:
>
> > kakimoto at tpg.com.au wrote:
> > > hello, all,
> >
> > >  I have a method in my controller which adds entries.
> >
> > >  The method is setup to match the path of
> > 'users/subscriptions/add'.
> >
> > >  Upon successfully adding entries, I want the same method to be
> > executed
> > > again (only that the method will know which template (view) to
> > call. I
> > > tried using a detach (and even a forward) and I keep getting an
> > error of
> > > , 'Couldn't forward to command "/users/subscriptions/add": Invalid
> > > action or component.'
> >
> > This is because the  path you specified is not the internal path
> > name to the action (that is whatever you named your controller
> > /create),
> > but it is the external path. Detach works on internal path names.
> >
> > > Reason why I am issuing a detach - To prohibit users from pressing
> > > "Refresh" on the browser which will cause the application to readd
> > the
> > > entry again into the database (this happens because I suspect that
> > the
> > > request object is not flushed. I could easily kill off the
> > parameters in
> > > the request object but I figured I use a detach and have another
> > (view)
> > > template show up.
> >
> > Detach will simply cause another action to be executed before
> > returning
> > to the browser, so this won't solve your problem. You need to cause
> > a
> > redirect to solve your problem, so the correct code would be:
> >
> > $c->res->redirect($c->uri_for_action('/controller/create')
> >
> > Where controller is the name of the controller that contains the
> > action
> > you provided in your email.
> >
> > Hope that helps
> >
> > --
> >     Oliver Charles / aCiD2
> >
> > _______________________________________________
> > List: Catalyst at lists.scsys.co.uk
> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> > Searchable archive:
> > http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> > Dev site: http://dev.catalyst.perl.org/
> >
> >
> >
>
>
>
>
>
Please don't top-post, put your reply at the bottom of the thread.

$c->detach is basically "$c->forward, and stop running".

If you have code:
sub some_action : Private {
  $c->forward('foo');
  $c->log->debug("Hello");
}
The debug message is printed.

However, with this code:
sub some_action : Private {
 $c->detach('foo');
 $c->log->debug("Hello");
}
The debug message is NOT printed.

$c->detach stops the path of execution right then, it doesn't continue at
all.

But, on the original subject, neither $c->forward or $c->detach do what you
are asking them to.  You want $c->res->redirect, and probably right after
->redirect add in $c->detach to stop the action's execution.

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090427/3242e=
fa1/attachment.htm


More information about the Catalyst mailing list