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

oliver.g.charles at googlemail.com oliver.g.charles at googlemail.com
Sat Apr 25 15:27:44 GMT 2009


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



More information about the Catalyst mailing list