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

Ian Wells ijw at cack.org.uk
Mon Apr 27 17:35:42 GMT 2009


2009/4/27  <kakimoto at tpg.com.au>:
> Hello, J. Shirley,
>
>  Thank you for your explaination. It made things much clearer and
> confirmed a lotta things.

Akimoto-san,

people have been answering the questions that you've asked, but I
wanted to check up what it is that you're trying to do.

Tell me if I have this right:

1. the problem you're trying to avoid:

Web browser asks for /user/subscriptions/add, posting parameters, in
order to create a new row in the DB.
=> On the server, your website code creates a new row in the DB
=> Server outputs a list of objects.

Guy using web browser presses refresh, to show the list again
=> On the server, your website code creates a new row in the DB (which
the user didn't want).
=> Server outputs a list of objects.

2. the way you're trying to avoid it

I'm not quite sure *what* you're trying to do, but it's a bit
confused, so let's sklip to


3. the way you *should* be doing it

Web browser asks for /user/subscriptions/add, posting parameters, in
order to create a new row in the DB.
=> On the server, your website code creates a new row in the DB
=> Server outputs a redirect to a page that lists the objects, let's
say /user/subscriptions/list and calls detach() without outputting a
page at all.   (No template is called.)

Web browser receives redirect, asks for the page that lists the
objects. at /user/subscriptions/list
=> Server outputs a list of objects.

Guy using web browser presses refresh, to show the list again (and
note that because of the redirect this now loads
/user/subscriptions/list)
=> Server outputs a list of objects.


People are steadily trying to steer you towards (3) above.  In (3) you
shouldn't be passing all the parameters to the create operation to the
list page (e.g. the new object name doesn't need to go to the list
page), so they shouldn't be on the redirect.  However, you might have
filters and sort arguments for the list that should be passed on -
typically these are added to the redirect URL rather than passed on in
the stash.  You might also have a message you want to print, reporting
on the *immediately preceding* operation that created the object,
there.  *That* would go in the flash.

Does that help?

Cheers,
-- 
Ian.



More information about the Catalyst mailing list