Tuesday, March 3, 2009

Re: Brain sprain

On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil <rhythmicdevil@gmail.com> wrote:
>
> Hi,
> I am having a brain sprain. I have a controller Subscribers that has
> two actions 'view' and 'add_device'. View is called from the index
> page with a Subscriber ID and then shows all the Subscriber's details.
> In the 'view' view there is a form to add a device. This form's action
> points at 'subscribers/add_device' and passes the subscriber_id and
> the device_id.
>
> If the device_id is empty I want to send the user back to the 'view'
> view (I have to change that name) populated with the Subscriber's
> data. For some reason I cant figure out how to do that in a simple
> way. Because each call to a view is separate request the data does not
> persist. Would someone be so kind as to point out the obvious to me?

Usually, the way this sort of thing is handled is to put the form in
the "add" view. This way, if the save fails, Cake can simply
re-display the form. If it succeeds, a redirect occurs.

Would it be possible to put a regular link in the "view" view that
pointed to controller::add_device()? You could append the
subscriber_id to the URL. Or, you could use a hidden field in a form
with a GET method.

So, things would look something lie this:

request:
/subscribers/view/:id

display:
the subscriber's info, plus link/form to add device

request:
/subscribers/add_device/:id

display:
the form

If the POST fails, you simply don't redirect and Cake will re-display
the same form, though with an error msg if you've set that up.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: