CakePHP Controller::edit method


/ Published in: PHP
Save to your folder(s)

This is the basic edit action suggested by the CakePHP Manual


Copy this code and paste it in your HTML
  1. function edit($id)
  2. {
  3.  
  4. //Note: The property model is automatically loaded for us at $this->Property.
  5.  
  6. // Check to see if we have form data...
  7. if (empty($this->data))
  8. {
  9. $this->Property->id = $id;
  10. $this->data = $this->Property->read();//populate the form fields with the current row
  11. }
  12. else
  13. {
  14. // Here's where we try to save our data. Automagic validation checking
  15. if ($this->Property->save($this->data['Property']))
  16. {
  17. //Flash a message and redirect.
  18. $this->flash('Your information has been saved.',
  19. '/properties/view/'.$this->data['Property']['id'], 2);
  20. }
  21. //if some fields are invalid or save fails the form will render
  22. }
  23. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.