Posted By

jesse on 04/04/08


Tagged

edit php cakephp cake crud


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Wiederkehr
travisa86


CakePHP Controller::edit method


 / Published in: PHP
 

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

This is the basic edit action suggested by the CakePHP Manual

  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. }

Report this snippet  

You need to login to post a comment.