vinn vinn - 1 year ago 110
reST (reStructuredText) Question

codeigniter restful api returning empty array

I am trying to fetch items by id but instead its returning null array.The code works fine when I fetch all the items.

Here is the controller:

class Search extends REST_Controller
{

function __construct()
{
// Construct the parent class
parent::__construct();
$this->load->model('Courses_model');
$this->load->model('Courses_category_model');
$this->load->model('Courses_lessons_model');
$this->load->model('Courses_photos_model');
$this->load->model('Providers_model');
}

function index_get()
{
$category_id = $this->get('category_id');

$result = $this->Courses_model->get_courses_category($category_id);
$this->response([
'status' => TRUE,
'data' => $result
], REST_Controller::HTTP_OK);

}
}


and the model file is here and the model file is here:

class Courses_model extends CI_Model
{
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
}

public function get_courses_category($category_id)
{
$this->db->where('category_id', $category_id);
$query = $this->db->get('courses');
return $query->result();
}

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download