public function saveTodo(Todo $todo) { $data = array('title' => $todo->getTitle(), 'description' => $todo->getDescription(), 'completed' => $todo->getCompleted()); $id = (int) $todo->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getTodo($id)) { $this->tableGateway->update($data, array('id' => $id)); } else { throw new \Exception("Todo {$id} doesn't exist"); } } }