Webservice ( Error ที่บรรทัด $id = $this->widgets_model->createWidget($data); )
function post()
{
$data = $this->_post_args;
try {
$id = $this->widgets_model->createWidget($data);
//$id = 3; // test code
//throw new Exception('Invalid request data', 400); // test code
//throw new Exception('Widget already exists', 409); // test code
} catch (Exception $e) {
// Here the model can throw exceptions like the following:
// * For invalid input data: new Exception('Invalid request data', 400)
// * For a conflict when attempting to create, like a resubmit: new Exception('Widget already exists', 409)
$this->response(array('error' => $e->getMessage()), $e->getCode());
}
if ($id) {
$widget = array('id' => $id, 'name' => $data['name']); // test code
//$widget = $this->widgets_model->getWidget($id);
$this->response($widget, 201); // 201 being the HTTP response code
} else
$this->response(array('error' => 'Widget could not be created'), 404);
}