0

I got 500 internal server error in CodeIgniter. It fine when I don't write $this->load->model("xxxx"); . I just got error message cause I didn't load my model at my controller

but when I load my model, error 500 happens

this is ajax in CodeIgniter. I've tried not using ajax and I able to insert.

 public function add(){
         //data blablabla
         //data blablabla
         //data blablabla
         //data blablabla

         $this->load->model("Training_model"); //when i wirte it, error happen
         $this->Training_model->save($data);

         return response()->json($data);
 }

no respond data available

this is might be simple but I can't find the solution. I am really newbie and new into this


EDIT DONE , JUST ERROR BUT FINE , I STILL ABLE TO INSERT , thanks for coming

Aksen P
  • 4,564
  • 3
  • 14
  • 27

3 Answers3

0

please load model in your construction class

 ``
 function _construct(){
   $this->load->model("Training_model");
 }
 ``
 ``
  public function add(){
        //data blablabla
        //data blablabla
        //data blablabla
        //data blablabla
  //  $this->load->model("Training_model"); //when i wirte it, error happen
    $this->Training_model->save($data);
    return response()->json($data);
  }
 ``
0

If your model is located in a sub-directory, include the relative path from your models directory. For example, if you have a model located at application/models/blog/Queries.php you’ll load it using:

$this->load->model('blog/queries');

And this is docs from Codeigniter:

(https://www.codeigniter.com/user_guide/general/models.html#loading-a-model)

Serghei Leonenco
  • 3,478
  • 2
  • 8
  • 16
0

i change my controller

         return response()->json($data);

into

        $response = $this->curl->simple_get($url);
        $status= json_decode($response, true);