芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/www/breadwinnerv2/application/controllers/Rest.php
methods['users_get']['limit'] = 500; // 500 requests per hour per user/key $this->methods['users_post']['limit'] = 100; // 100 requests per hour per user/key $this->methods['users_delete']['limit'] = 50; // 50 requests per hour per user/key $this->load->model('restservice_model', 'restservice'); } public function clients_get() { $id = $this->get('id'); if ($id === NULL) { $list = $this->restservice->customers(); if ($list) { // Set the response and exit $this->response($list, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code } else { // Set the response and exit $this->response([ 'status' => FALSE, 'message' => 'No users were found' ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code } } // Find and return a single record for a particular user. $id = (int)$id; // Validate the id. if ($id <= 0) { // Invalid id, set the response and exit. $this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code } // Get the user from the array, using the id as key for retrieval. // Usually a model is to be used for this. $list = $this->restservice->customers($id); if (!empty($list)) { $this->set_response($list[0], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code } else { $this->set_response([ 'status' => FALSE, 'message' => 'User could not be found' ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code } } public function clients_post() { $id = $this->post('id'); if ($id === NULL) { $list = $this->restservice->customers(); // Check if the users data store contains users (in case the database result returns NULL) if ($list) { // Set the response and exit $this->response($list, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code } else { // Set the response and exit $this->response([ 'status' => FALSE, 'message' => 'No users were found' ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code } } // Find and return a single record for a particular user. $id = (int)$id; // Validate the id. if ($id <= 0) { // Invalid id, set the response and exit. $this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code } // Get the user from the array, using the id as key for retrieval. // Usually a model is to be used for this. $list = $this->restservice->customers($id); if (!empty($list)) { $this->set_response($list[0], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code } else { $this->set_response([ 'status' => FALSE, 'message' => 'User could not be found' ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code } } public function clients_delete() { $id = (int)$this->get('id'); // Validate the id. if ($id <= 0) { // Set the response and exit $this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code } if ($this->restservice->delete_customers($id)) { $message = [ 'id' => $id, 'message' => 'Deleted the resource' ]; $this->set_response($message, REST_Controller::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code } } }