Issue
I have an API that's working fine without this data range in URL, but now I need to set to better search, as this example, after /orders.
E.g.: http://localhost/ws/v1/orders?fromDate=2019-01-01&toDate=2019-12-31
Controller:
public function getOrders_get($id = 0){
header("Access-Control-Allow-Origin: *");
// Load Authorization Token Library
$this->load->library('Authorization_Token');
/**
* User Token Validation
*/
$is_valid_token = $this->authorization_token->validateToken();
if (!empty($is_valid_token) AND $is_valid_token['status'] === TRUE)
{
if (empty($id)){
$data = $this->db->get("order_view")->result();
}else{
$data = $this->db->get_where("order_view", ['id' => $id])->row_array();
}
$this->response($data, REST_Controller::HTTP_OK);
} else {
$this->response(['status' => FALSE, 'message' => $is_valid_token['message'] ], REST_Controller::HTTP_NOT_FOUND);
}
}
Solution
You can add a between to you sql.
$from_date = $_GET['fromDate'];
$to_date = $_GET['toDate'];
...
$this->db->where("date between $from_date and $to_date");
Answered By - LF00
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.