>From the book:
"One thing to note here: CakePHP will assume that you are editing a
model if the 'id' field is present in the data array. If no 'id' is
present (look back at our add view), Cake will assume that you are
inserting a new model when save() is called."

So, you'd have to add that hidden field to your view in order this to
work, but can leave the code in the controller as is

On Oct 6, 12:40 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
> I see what you are saying, I haven't tried this yet. However this
> seems very hacky to me with the way most things are done in CakePHP.
> Is this really the way I should go about solving this issue?
>
> On Oct 6, 3:57 am, vekija <vedran.konto...@gmail.com> wrote:
>
> > try removing $this->Message->id = $id; and adding parameters to read
> > function at the bottom
>
> > $this->data = $this->Message->read(null, $id);
>
> > and placing a hidden input file in your form for message id
>
> > echo $form->hidden('Message.id');
>
> > On Oct 6, 11:22 am, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > So, my subject name might be misleading. This is why I'm posting on
> > > here because I don't have much of an idea of what to search for in
> > > order to find a solution.
>
> > > So here is my issue. I have a controller with an edit function. The
> > > page loads fine, it edits fine, and it invalidates fields fine, and it
> > > shows which fields had the error fine. However that's where the
> > > problem starts that I noticed. If a user types in data that gets
> > > invalidated, and then tries to submit it again, it brings up an error
> > > that the $id field is missing from the argument (the url), and it is
> > > missing. If the user invalidates some data, corrects the issue, and
> > > then clicks submit, the data isn't saved but it says it was saved
> > > correctly.
>
> > > So my question is, what can I do so that a user can get an invalidated
> > > message, but everything will continue working as it is supposed to.
> > > Here is my code for the edit function, if you need anything else
> > > please just ask.
>
> > >                 function edit($id)
> > >                 {
> > >                         $this->Message->id = $id;
>
> > >                         if (!empty($this->data['Message']))
> > >                         {
> > >                                 $mrClean = new Sanitize();
> > >                                 $this->data['Message']['message'] = 
> > > $mrClean->clean($this->data
> > > ['Message']['message'], array('encode' => 0, 'escape' => 0));
> > >                                 $this->data['Message']['modified'] = 
> > > date('Y-m-d G:i:s');
>
> > >                                 if 
> > > ($this->Message->save($this->data['Message']))
> > >                                 {
> > >                                         $this->Session->setFlash('The 
> > > Pastors Message has been edited.');
>
> > >                                         $this->redirect('/');
> > >                                         $this->exit();
> > >                                 }
> > >                                 else
> > >                                 {
> > >                                         $this->Session->setFlash('The 
> > > Pastors Message could not be
> > > edited.');
> > >                                 }
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->data = $this->Message->read();
> > >                         }
> > >                 }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to