/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function addedit($id = null) { if($id) { // Edit data, populate fields $this->data = $this->Model->read(null, $id); } else { // Create, prefill some fields.. $the_user = $this->Auth->user(); $this->data['Model']['user_id'] = $the_user['User']['id']; } } else { if($id == null) { // Create model $this->Model->create(); } if ($this->Article->save($this->data)) { $this->Session->setFlash(__('The Article has been saved', true)); // Add this to form: // echo $form->submit(__('Save and close', true), array('name'=>'close')); } if($id == null) { $new_id = $this->Model->getInsertID(); } $this->data = $this->Model->read(null, $id); } else { $this->Session->setFlash(__('The Model could not be saved. Please, try again.', true)); } } }
Comments
