Ability to edit event via api by passing in array

This commit is contained in:
Kyle Johnson 2014-04-25 18:20:55 +00:00
parent 78ef09705d
commit 2e3900d1c7
1 changed files with 11 additions and 8 deletions

View File

@ -72,19 +72,22 @@ class EventsController extends AppController {
* @return void
*/
public function edit($id = null) {
$this->Event->id = $id;
if (!$this->Event->exists($id)) {
throw new NotFoundException(__('Invalid event'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Event->save($this->request->data)) {
return $this->flash(__('The event has been saved.'), array('action' => 'index'));
}
if ($this->Event->save($this->request->data)) {
$message = 'Saved';
} else {
$options = array('conditions' => array('Event.' . $this->Event->primaryKey => $id));
$this->request->data = $this->Event->find('first', $options);
$message = 'Error';
}
$monitors = $this->Event->Monitor->find('list');
$this->set(compact('monitors'));
$this->set(array(
'message' => $message,
'_serialize' => array('message')
));
}
/**