Return to Snippet

Revision: 5797
at April 4, 2008 20:12 by jesse


Initial Code
function edit($id)
{

   //Note: The property model is automatically loaded for us at $this->Property.

   // Check to see if we have form data...
   if (empty($this->data))
   {
        $this->Property->id = $id;
        $this->data = $this->Property->read();//populate the form fields with the current row
   }
   else
   {
      // Here's where we try to save our data. Automagic validation checking
      if ($this->Property->save($this->data['Property']))
      {
         //Flash a message and redirect.
         $this->flash('Your information has been saved.',
                     '/properties/view/'.$this->data['Property']['id'], 2);
      }
      //if some fields are invalid or save fails the form will render
   }
}

Initial URL
http://manual.cakephp.org/chapter/models

Initial Description
This is the basic edit action suggested by the CakePHP Manual

Initial Title
CakePHP Controller::edit method

Initial Tags
php, cakephp

Initial Language
PHP