我有一个设置,要求对集合进行计数,但我总是收到
的错误{“状态”:false}
我的模型如下:
public function count_users() {
$query = $this->mongo_db->get('users');
$row_count = count($query);
$data = $row_count;
$return = [
'status' => true,
'data' => $data
];
}
我的控制器就是这样:
// **
// ** List Todays Stats for Admin Panel
// **
public function todaysstats_get() {
//Validate user - logged in as admin -- session required
$this->session_model->check_session();
//Count Users
$data = $this->admin_model->count_users();
$http = $this->data_model->status_to_http_response($data['status']);
$data['status'] = $http['status'];
$http_response = $http['http_response'];
$this->set_response($data, $http_response);
}
我正在使用GET
方法来获取简单的计数返回数字
$route['v1/admin/todaysstats'] = 'v1/admin/todaysstats';
我尝试了几种不同的方法,但似乎并没有改变REST
请求的状态。
$http = $this->data_model->status_to_http_response($data['status']);
public function status_to_http_response($status) {
// Select appropriate HTTP Response code, based on "status"
// true ---> 200
// false ---> 422 (usually a validation error)
// else ---> use the value in "status" and set "status" to false.
$status = intval($status);
// If "true" send back a 200
if ($status == 1) {
$http = REST_Controller::HTTP_OK;
$status = true;
}
// If "false" send back a 422
elseif ($status == 0) {
$http = REST_Controller::HTTP_UNPROCESSABLE_ENTITY;
$status = false;
}
// Otherwise use the status code given
else {
$http = $status;
$status = false;
}
return [
'http_response' => $http,
'status' => $status,
];
}