RE: Brain sprain
That was the trick. Thanks Brian. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of brian Sent: Wednesday, March 04, 2009 12:12 AM To: cake-php@googlegroups.com Subject: Re: Brain sprain Actually, I just realised that you could call $this->setAction('view', $user_id) instead of redirecting. On Tue, Mar 3, 2009 at 11:42 PM, Steven Wright wrote: > > Well the only issue is that the client wants all the data and the add > device on the same view. There will possible be more mini forms as > well. I would prefer to break it up into logical chunks but its not my call. > > Would AJAX get me out of this? If I only have to update a region of > the page its different than a redirect. > > > > > -Original Message- > From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On > Behalf Of brian > Sent: Tuesday, March 03, 2009 9:17 PM > To: cake-php@googlegroups.com > Subject: Re: Brain sprain > > > On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil > > 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
RE: Brain sprain
Awesome I am going to try that now. I was also thinking since its essentially the same view it should also be the same action. I could just write a switch in the action that reads a hidden field in the form and then process accordingly. Not very pretty but it should work. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of brian Sent: Wednesday, March 04, 2009 12:12 AM To: cake-php@googlegroups.com Subject: Re: Brain sprain Actually, I just realised that you could call $this->setAction('view', $user_id) instead of redirecting. On Tue, Mar 3, 2009 at 11:42 PM, Steven Wright wrote: > > Well the only issue is that the client wants all the data and the add > device on the same view. There will possible be more mini forms as > well. I would prefer to break it up into logical chunks but its not my call. > > Would AJAX get me out of this? If I only have to update a region of > the page its different than a redirect. > > > > > -Original Message- > From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On > Behalf Of brian > Sent: Tuesday, March 03, 2009 9:17 PM > To: cake-php@googlegroups.com > Subject: Re: Brain sprain > > > On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil > > 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Brain sprain
Actually, I just realised that you could call $this->setAction('view', $user_id) instead of redirecting. On Tue, Mar 3, 2009 at 11:42 PM, Steven Wright wrote: > > Well the only issue is that the client wants all the data and the add device > on the same view. There will possible be more mini forms as well. I would > prefer to break it up into logical chunks but its not my call. > > Would AJAX get me out of this? If I only have to update a region of the page > its different than a redirect. > > > > > -Original Message- > From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf > Of brian > Sent: Tuesday, March 03, 2009 9:17 PM > To: cake-php@googlegroups.com > Subject: Re: Brain sprain > > > On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil > 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
RE: Brain sprain
Well the only issue is that the client wants all the data and the add device on the same view. There will possible be more mini forms as well. I would prefer to break it up into logical chunks but its not my call. Would AJAX get me out of this? If I only have to update a region of the page its different than a redirect. -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of brian Sent: Tuesday, March 03, 2009 9:17 PM To: cake-php@googlegroups.com Subject: Re: Brain sprain On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Brain sprain
On Tue, Mar 3, 2009 at 3:55 PM, RhythmicDevil 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
RE: Brain sprain
Hi Gonzalo thanks for the answer. Unfortunately I dont think that will work. The Set method will set the value for the current request but when the redirect happens that variable is lost because the redirect is a new request. The only way I can think to do this is to set the variable into the GET request string or stuff it in the SESSION. Both of those seem like I am missing something that CakePHP would do for me if I could find the page in the manual. _ From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of Gonzalo Servat Sent: Tuesday, March 03, 2009 3:59 PM To: cake-php@googlegroups.com Subject: Re: Brain sprain On Tue, Mar 3, 2009 at 6:55 PM, RhythmicDevil wrote: [..snip..] 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? Maybe this is what you want: http://api.cakephp.org/class/controller#method-ControllersetAction - Gonzalo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Brain sprain
On Tue, Mar 3, 2009 at 6:55 PM, RhythmicDevil wrote: > > [..snip..] > > 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? > Maybe this is what you want: http://api.cakephp.org/class/controller#method-ControllersetAction - Gonzalo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Brain sprain
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? In reality I should probably do a validation on the client, but this case would still have to be handled after a device is added. I would want the user sent back to the 'view' view to see the updated data. Thanks. Steve pageTitle = 'Subscriber'; $this->layout = 'default'; } function view() { debug($this->data); if(! empty($this->data['Subscriber']['subscriber_id'])) { if(! $data = $this->Subscriber->fetchSubscriber($this->data ['Subscriber']['subscriber_id'])) { $this->redirect('/subscribers/index'); // TODO no result handle this! } $this->set('subscriber', $data); $this->pageTitle = 'Subscriber'; $this->layout = 'default'; } else { $this->redirect('/subscribers/index'); } } function add_device() { $this->autoRender = false; //debug($this->data); if(! empty($this->data['Subscriber']['device_id'])) { // handle adding the device debug($this->data); // Then reroute back to the view } else { $this->redirect(array('controller' => 'subscribers', 'action' => 'view')); } } } ?> --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---