0

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();
}
Vincent Kituyi
  • 119
  • 2
  • 17

2 Answers2

0

i have seem u r question and find out ans please check the below link i think help u.

https://github.com/chriskacerguis/codeigniter-restserver/blob/master/application/libraries/REST_Controller.php

RestApi Post request using CodeIgniter

0

hahaa. Finally, after a little snap I solved this. I just defined the routes and it worked like a charm.

Vincent Kituyi
  • 119
  • 2
  • 17